gcc 4.4.4 c89
I am just wondering is there any standard that should be followed when creating types.
for example:
typedef struct date
{
} date_t;
I have also seen people put a capital like this:
typedef struct date
{
} Date;
Or for variables
typedef unsigned int Age;
or this
typedef unsigned int age_t;
Is there any standard that should be followed. Personally I prefer post fixing with a _t.
Many thanks for any suggestions,
The C language contains the typedef keyword to allow users to provide alternative names for the primitive (e.g., int) and user-defined (e.g struct) data types. Remember, this keyword adds a new name for some existing data type but does not create a new type.
Function, typedef, and variable names, as well as struct, union, and enum tag names should be in lower case.
typedef is a reserved keyword in the programming languages C and C++. It is used to create an additional name (alias) for another data type, but does not create a new type, except in the obscure case of a qualified typedef of an array type where the typedef qualifiers are transferred to the array element type.
typedef is used to define new data type names to make a program more readable to the programmer. For example: | main() | main() { | { int money; | typedef int Pounds; money = 2; | Pounds money = 2 } | } These examples are EXACTLY the same to the compiler.
If you are working on a platform that follows POSIX standards you should be aware that any identifier ending in _t
is reserved for POSIX defined types so it is not advisable to follow the same convention for your own types.
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