[LC++]sizeof...

ianezz at kinsale.sodalia.it ianezz at kinsale.sodalia.it
Tue Aug 6 01:26:05 UTC 2002


Usando la tastiera di Palaka, Sasidhar, uno sconosciuto ha scritto:

 > But, say if I am interested in implementing 'sizeof' as an exercise
 > question, 
 > Is there any other way out apart from what I suggested?

Well, you could try

    int * p;
    int * q;
    
    q = p + 1;
   
    return (unsigned long)q - (unsigned long)p;

assuming that strange things don't happen when casting a pointer into
an unsigned long.

Or even

    int * p;
    int * q;
    
    q = p + 1;
   
    return (char *)q - (char *)p;

since sizeof(char) should always be 1 byte. 




-- 
 |   \    \  | ___|_  |_  | ianezz AT sodalia.it
 |  _ \  | \ | _|    /   /  Visita il LinuxTrent a
_|_/  _\_|  _|____|___|___| http://www.linuxtrent.it




More information about the tuxCPProgramming mailing list