[LC++]sizeof...

Palaka, Sasidhar psasi at corp.untd.com
Mon Aug 5 23:11:05 UTC 2002


How about implementing this way,
Say, you want to know the size of 'char'.
Look at the following skeleton code.

char* p;
char* q,
q = p+1;
return q-p;

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




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


Goverthanan, pigiando tasti a caso sul citofono, ha scritto:

 > Can anyone tell me whats the alternative for sizeof function i can
 > use to get the size of the variable...

sizeof() is an operator of the language, not a function, and unless
you know in advance how many bytes a certain type requires, there's no
way around it (i.e. only the compiler knows -- this is true expecially
for structs and classes).

May I ask you why are you trying to avoid using sizeof()?

-- 
 |   \    \  | ___|_  |_  | 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