typedef and variable names

Viewed 2175

Ignoring why I would want to do this, just trying to understand what is happening here: This code compiles:

#include <stdio.h>
typedef char byte;

int main (void) 
{
    byte var_byte;
    int byte = 10;

    printf("\n Test program: %d\n", byte);
}  

But, if I change the order in which the variables are declared, it does not compile.

This DOES NOT COMPILE:

#include <stdio.h>
typedef char byte;

int main (void)
{
    int byte = 10;
    byte var_byte;

    printf("\n Test program: %d\n", byte);
}

Compiler error:

b.c:7:8: error: expected ‘;’ before ‘var_byte’
   byte var_byte;
        ^~~~~~~~

Could someone please explain why order matters?

2 Answers
Related