As far as I know:
an underscore (‘_’) and all identifiers regardless of use that begin with either two underscores or an underscore followed by a capital letter are reserved names
In Posix: Names that end with ‘_t’ are reserved for additional type names.
In addition: The header file sys/stat.h reserves names prefixed with ‘st_’ and ‘S_’.
Can we use "t_whatever" (e.g. t_node) to define our own types?
Yes, you can certainly use t_ as a prefix, that's not in any reserved space.
Personally I wouldn't recommend doing so, but that's mainly because I'm not convinced that having a prefix to make a type name more obviously a type name is a win, in very many cases.
I can't see that
t_node head;
is better than
node head;
In fact, I think the latter is more readable. It's very often the case that you see from usage immediately if a word is a type or variable name in C, in my opinion.
One objection might be that it can be unclear when using sizeof, for instance consider dynamically allocating a new node. Many people would write that as:
t_node *head = malloc(sizeof(t_node));
but I'm very set against that usage; I consider it better to avoid handing type names to sizeof whenever possible, and use the variable instead, thus "locking" the size to the destination type which is a good thing:
node *head = malloc(sizeof *head);
Also, as usual, note that I would never write the first example exactly like that, since I think it makes sizeof look like a function. I always have a space:
t_node *head = malloc(sizeof (t_node));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With