tags:

views:

90

answers:

4

Hi, I'm newbie in programming especially c and c++.

I often saw VARNAME_P and VARNAME_T in c/c++. What are the difference between those two?

Thanks in advance

+1  A: 

Are you referring to the type naming convention, where a type or pointer to a type has _t or _p appended to it respectively? If so, there are no differences. If you think about it, there can't be, considering that these conventions have whatever meaning you decide to attach to them. For example, I may decide that all my variables that deal with length will have l_ as a prefix.

Alexander Rafferty
+4  A: 

They're mostly just convention for names. The language itself defines a few types like size_t, which is the type to be used for storing the sizes of things, or ptrdiff_t the type for storing the differences between pointers.

The _p suffix is most likely a pointer type like:

typedef int * INT_P;

so you could replace all your:

int *xyz = NULL;

lines with:

INT_P xyz = NULL;

I don't ever recall seeing the _p suffix in the actual standard so that's just user convention, no different to mine, which is to use p and t as prefixes:

typedef struct {
    char name[100];
    int age;
} tPerson;
char *pBuff = maloc (sizeof (tPerson));
paxdiablo
+5  A: 

By convention, _t is a suffix that means "type", so any type might have this suffix. _p usually means "pointer", so it indicates a type that is a pointer to a given type.

Brian Campbell
+1  A: 

There is no such thing like C/C++. These are two different language with probably differing naming conventions.

The suffix _t in identifier names is meant to indicate that this identifier is a typedef. Usually they alias some of the standard types, in a way that is suitable for the concrete platform your are dealing with.

These names are generally reserved: the C standards define some of them, and the POSIX standard requires all such names to be reserved for future use by extensions of that standard.

Thus it is a bad idea to declare such identifiers in your own code, especially for something that is not a typedef.

Jens Gustedt