views:

472

answers:

2

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?

+2  A: 

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.

Michael Aaron Safyan
_t is indeed reserved by POSIX
William Pursell
Now that two people said it. I double-checked, and it turns out you are right. I'm going to fix that.
Michael Aaron Safyan
_t is not reserved by POSIX in the sense that nobody else is allowed to use such names. Rather POSIX implementations may only use types names of this form.
starblue
Actually, please see:http://www.gnu.org/s/libc/manual/html_node/Reserved-Names.htmlAccording to the document:"Names that end with ‘_t’ are reserved for additional type names. "Of course, if one always prefixes one's function and type names with the name of their library (e.g. "mylibrary_suchandsuchtype_t"), it is very unlikely that they will have a conflict with future versions of the C standard library.
Michael Aaron Safyan
A: 

I use the naming conventions used in Dave Hanson's C Interfaces and Implementations: a type is named with the module name and a capital T. So for example, the type of sequences is Seq_T, and the type of hash tables is Table_T. Within the implementation of a module Hanson uses #define to abbreviate just to T. This is basically Modula-3 conventions applied to C programming, but I find that after a brief initial shock it works well.

Norman Ramsey