typedef and variable names

前端 未结 2 1270
离开以前
离开以前 2021-01-18 22:14

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

#include 
typedef char byte;

int          


        
2条回答
  •  孤独总比滥情好
    2021-01-18 22:56

    Edit here: (misunderstand of the question)

    When you declare a variable in C it does not look for typedef structures to see if a structure named the same with the variable. On the first code,

    byte var_byte; 
    

    this line of code comes before the declaration of the variable int byte. The computer will look for the most recent reference of the word byte as it was the structure name here.

    On the second one the the variable int byte does not return an error because you can still create variables with the same structure type name in C. But after you do so you can't create new structures to that structure as the computer will think that it is referring to the variable name and not the the structure type as the variable was declared most recently

提交回复
热议问题