According to this stack overflow answer, the “_t” postfix on type names is reserved in C. When using typedef to create a new opaque type, I’m used to having some sort of indication in the name that this is a type. Normally I would go with something like hashmap_t but now I need something else.
Is there any standard naming scheme for types in C? In other languages, using CapsCase like Hashmap is common, but a lot of C code I see doesn’t use upper case at all. CapsCase works fairly nicely with a library prefix too, like XYHashmap.
So is there a common rule or standard for naming types in C?
Yes, POSIX reserves names ending
_tif you include any of the POSIX headers, so you are advised to stay clear of those – in theory. I work on a project that has run afoul of such names two or three times over the last twenty or so years. You can minimize the risk of collision by using a corporate prefix (your company’s TLA and an underscore, for example), or by using mixed case names (as well as the_tsuffix); all the collisions I’ve seen have been short and all-lower case (dec_t,loc_t, …).Other than the system-provided (and system-reserved)
_tsuffix, there is no specific widely used convention. One of the mixed-case systems (camelCase or InitialCaps) works well. A systematic prefix works well too – the better libraries tend to be careful about these.If you do decide to use lower-case and
_tsuffix, do make sure that you use long enough names and check diligently against the POSIX standard, the primary platforms you work on, and any you think you might work on to avoid unnecessary conflicts. The worst problems come when you release some nameexample_tto customers and then find there is a conflict on some new platform. Then you have to think about making customers change their code, which they are always reluctant to do. It is better to avoid the problem up front.