#define vs typedef
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
In contrast a typedef like this:
typedef char* char_ptr;
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 02:01 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.