Velocity Reviews

Velocity Reviews (
-   C Programming (
-   -   #define vs typedef (

sophia 04-27-2008 07:44 AM

#define vs typedef
Dear all,

the following are the differences b/w #define and typedef ,which i
have seen in Peter van der lindens book. is there any other difference
between thes two ?

The right way to think about typedef as being a complete encapsulated
type - you can't add to it after you have declared it.


#define peach int
unsigned peach i; /*works fine*/

typedef int banana ;
unsigned banana i; /*illegal*/

a typedef'd name provides the type for every declarator in a


#define int_ptr int*
int_ptr chalk, cheese;

after macro expansion, the second line effectively becomes
int* chalk,cheese;

In contrast a typedef like this:

typedef char* char_ptr;
char_ptr bentley,rolls_royce;

declares both bentley and rolls_royce to be the same . the name on the
front is different, but they are both a pointer to a char.

All times are GMT. The time now is 12:31 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.