Confused by #define and typedef

后端 未结 4 2145
鱼传尺愫
鱼传尺愫 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:47

    The preprocessor does only do text-substitutions, so that code would look like

    typedef struct Stack_T *Stack_T;
    

    So every T in your code is first replaced to Stack_T, and after that your compiler kicks in, sees the typedef and uses struct Stack_T*.

    It might be good to know that struct Type and Type are only the same in C++, not in C.

提交回复
热议问题