Confused by #define and typedef

后端 未结 4 2128
鱼传尺愫
鱼传尺愫 2021-01-07 01:27
#define T Stack_T
typedef struct T *T;

Then what does T in struct T mean,the one defined by #define or

4条回答
  •  时光取名叫无心
    2021-01-07 01:29

    #define directives are substituted early on in the compilation process (translation phase 4, compilation doesn't actually occur until phase 7, these phases and what happens during them are detailed in the standard, section 5.1.1.2).

    That #define will simply change T pre-processing tokens into Stack_T.

    The effect of that on the typedef will be to turn it into:

    typedef struct Stack_T *Stack_T;
    

    Following that, Stack_T is defined as a type, a pointer to another type of struct Stack_T. The Stack_T and struct Stack_T are two separate things.

提交回复
热议问题