Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

c - Naming scheme for typedefs

I'm working on a library that extensively used constructs like

typedef struct foo_bar_s {
    ...
} foo_bar_t;

It's a bad idea to use the _t suffix, because it's a POSIX reserved namespace. The _s suffix for structs is also pretty useless. So I thought I can change it all to

typedef struct foo_bar {
    ...
} foo_bar;

or if the struct name is not needed

typedef struct {
    ...
} foo_bar;

However, I cannot distinguish typedefs from regular symbols (variables, etc.) anymore. Is this really such a big deal and should I use a different suitable naming scheme for the typedefs? Or does it not matter that much?

I'm really not so sure. What do you think? Also, what recommendations do you have for typedef naming schemes?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Although, "_t" is reserved, it is very unlikely that you will encounter a problem. However, this convention is a remnant of older versions of C where this syntax was required in order to name structs, and so nowadays you can simply write something like the following (omitting the typedef and the typedef names):

struct name_of_struct
{
   type1 member1;
   type2 member2;
   // ...
   typeN memberN;
};

And yes, you can use single line comments ("//...") in the current standard of C.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...