Palaka, Sasidhar psasi at corp.untd.com
Tue Aug 6 01:01:05 UTC 2002

  Thanks for correcting me, you are right. I missed out that type casting
But, say if I am interested in implementing 'sizeof' as an exercise
Is there any other way out apart from what I suggested?


-----Original Message-----
From: ianezz at kinsale.sodalia.it [mailto:ianezz at kinsale.sodalia.it]
Sent: Monday, August 05, 2002 8:50 PM
To: tuxcpprogramming at lists.linux.org.au
Subject: RE: [LC++]sizeof...

Palaka, Sasidhar, pigiando tasti a caso sul citofono, ha scritto:

 > Basically the idea is to increment the pointer and then subtract to give
 > size.

Try it with an `int'... 

the difference between pointers is in bytes/sizeof(pointed type)... so
it gives back always `1'.

Of course you could try casting the pointers to some unsigned type
large enough before subtracting them, but then how do you know how
much is ``large enough''? 

Use sizeof() and live in peace.

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

This is the Linux C++ Programming List
: http://lists.linux.org.au/listinfo/tuxcpprogramming List

More information about the tuxCPProgramming mailing list