Alex Rivera | Logout

Standard for typedef'ing

Asked 2010-08-21T16:21:55.380
23

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,

Edit
Report

2 Answers

3

Follow what the rest of the people do for your project so everything stays consistent. Otherwise they're both acceptable technically.

answered 2010-08-21T16:26:18.053
1

In general most languages allow the use of SentenceCase for non-standardized classes or types. I find this is the best practise, and in languages that allow it, additionally use namespaces or modules to prevent clashes. In languages that don't (such as C), a prefix where necessary never goes astray. To use a multi-language example for something I'm currently working on:

C: typedef uint32_t CpfsMode;
C++: namespace Cpfs { typedef uint32_t Mode; }
Python: cpfs.Mode = int
answered 2010-08-21T17:30:29.447

Your Answer