This wont work for keywords as my_sizeof(int) or my_sizeof(char) gives an error. To find the sizeof keywords we need to define one more macro as fallows
#define sizeof_type(type) ((size_t)((type *)0+1) /Ganesh --- On Mon, 11/3/08, Rajath N R <[EMAIL PROTECTED]> wrote: From: Rajath N R <[EMAIL PROTECTED]> Subject: [c-forum] Re: [c-prog] how to find size without using sizeof?? To: [email protected], "c-form" <[EMAIL PROTECTED]> Date: Monday, November 3, 2008, 10:28 AM Hi, check this........ ......... ... #include <stdio.h> #include <sys/types.h> #define my_sizeof(var) ((size_t)(&(var) + 1) - (size_t)(&(var))) struct test { int a; int b; }; struct test a1; main() { int num; char ch; printf("%d\n" , my_sizeof(num) ); printf("%d\n" , my_sizeof(ch) ); printf("%d\n" , my_sizeof(a1) ); } Thanks & Regards, Rajath N R --- On Sun, 11/2/08, una_020 <[EMAIL PROTECTED] co.in> wrote: From: una_020 <[EMAIL PROTECTED] co.in> Subject: [c-prog] how to find size without using sizeof?? To: [EMAIL PROTECTED] com Date: Sunday, November 2, 2008, 7:28 AM 1.how to find size of structure without using sizeof operator? 2.variable name i.e. identifier is given how to find it's size without using sizeof? [Non-text portions of this message have been removed]
