![]() |
#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. ex:- #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 declaration Ex:- #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 10:25 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.