In this answer of mine, I used _t
at end of types, which ended at best, controversial. This is the practice I use in my current projects.
typedef struct {
int x;
int y;
} point_t;
This was intended to be consistent with C types from stddef.h
like size_t
or ptrdiff_t
. However, according to certain comments in my questions, _t
postfix appears to be reserved for POSIX. What should I use instead of _t
? Or should I continue using _t
anyway?
This question is for both C and C++. If these languages have different conventions, feel free to answer so.
4
There is no consensus within the C and C++ communities with regard to naming types.
Although the _t
suffix is indeed reserved by POSIX, some will advocate using the _t
suffix for your own types as well, while others will equally adamantly argue that you should not tempt fate by risking duplicate names with POSIX.
Alternative naming conventions suggest the use of a prefix for types, such as C
or T
.
I find suffixes rather ugly and so avoid _t
etc. A good alternative is to use a capital letter to start type names, so Point
in your example above.
4
It depends on you. Unless there is a conflict with the reserved words you are good to go. However, consider a scenario where you are working in a company and multiple people are accessing the same code base, and your code gets to a person who is not aware of your habit He/She can then assume that its a reserved type, especially if you write something like point_t. So, keep it simpler e.g. point is simpler than point_t. And if you want to append something to it, append you name initials.