Standard for typedef'ing

前端 未结 7 1997
清酒与你
清酒与你 2020-12-30 02:41

gcc 4.4.4 c89

I am just wondering is there any standard that should be followed when creating types.

for example:

typedef struct date
{
} dat         


        
7条回答
  •  别那么骄傲
    2020-12-30 03:04

    You may just simply use

    typedef struct toto toto;
    
    1. The struct toto (tag) and the typedef name toto (identifier) are in different C "namescopes" so they are compatible, but they point to the same type in the end.
    2. As an extra bonus this is also compatible with C++, which usually implicitly has such a typedef.
    3. As another bonus this inhibits to declare a variable toto which can be quite confusing at times.

提交回复
热议问题