Click to See Complete Forum and Search --> : Our Own code for Sizeof() operator


shivaj
July 8th, 2005, 08:00 AM
Hi all,

I tried for this and I am unable to get an idea, how to write my own code for sizeof.
My english is poor. pls understand.For to understand i am writing an example below:

main()
{
int i;
printf("size of integer is = %d",sizeof(i));
}

output:
size of integer is = 2

Now, here i want write my own function for to calute size of integer.

Thank u..

swtsvn
August 27th, 2009, 11:54 AM
how about this macro from another forum
i havent tried this out yet

#define mySizeof(x){__typeof__(x) tmp ;(char*)(&tmp + 1) - (char*)(&tmp);}

e.g
mySizeof(int)
int a;
mySizeof(a);

PeejAvery
August 27th, 2009, 02:25 PM
Welcome to the forums, swtsvn. :wave:

Please remember to keep your posts relevant. This thread is over 4 years old! :eek: