typedef

Posts 1–4 of 4 · Page 1 of 1
typedef
this is probably a stupuid question, but i never understood typedef. if i have something like this
Code:
typedef a *b;
would that be the same as
Code:
a * b;
whats the difference?
typedef changes the name of something.

typedef int INTEGER;
makes int INTEGER, so a dec for int would be
INTEGER variable = 9001;

though as far as i know it is only to keep consistency for MultiPlatform APIs and making lives easier so we do not need to write stuff like unsigned long every time.

typedef double dub;
dub DoubleVariable = 9001;

typedef unsigned long ULONG;
ULONG prettyLargeNumber = 9001;

same with pointer to stuff names

example
typedef char* pointer_to_a_character;
pointer_to_a_character String = "Hello";
cout << String;
Function pointers as well, this way you only have to type it out once.

Code:
int Add(int x,int y)
{
         return x+y;
}

typedef int (__cdecl* pAdd)(int,int); //__cdecl is C's usual calling convention
pAdd funcAdd = &Add

int main()
{
       int number = funcAdd(5,5); //this is actually pointing to Add()
       cout << number;   //output is 10
}
Just adding to Virtual Void's comment.
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us