Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard for typedef'ing

Tags:

c

typedef

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,

like image 968
ant2009 Avatar asked Aug 21 '10 16:08

ant2009


People also ask

What is typedef structure in C?

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.

Should typedef be capitalized?

Function, typedef, and variable names, as well as struct, union, and enum tag names should be in lower case.

Why is typedef used in C?

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.

What is typedef example?

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.


1 Answers

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.

like image 101
CB Bailey Avatar answered Sep 21 '22 18:09

CB Bailey