What are the differences between these two typedef styles in C?

后端 未结 6 1303
野趣味
野趣味 2021-01-11 14:24

I\'m curious what the difference here is when typedefing an enum or struct. Is there any difference semantically between these two blocks?

This:

typ         


        
6条回答
  •  南方客
    南方客 (楼主)
    2021-01-11 14:51

    Adding to user207442's comment, it's possible for a source code module to declare variables of type "struct foo *" without ever having a definition for the struct. Such a module will not be able to dereference such pointers, but may pass them to and from other modules.

    For example, one could have a header file define a type "USERCONSOLE" using "typedef struct _USERCONSOLE *USERCONSOLE;". Code that #include's that header file could have variables of type USERCONSOLE, and pass such variables to/from modules that know what a _USERCONSOLE really is, without the header file having to expose the actual definition of the structure.

提交回复
热议问题