TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: JAMIE KOWINSKY
date: 1997-10-29 18:26:00
subject: sizeof() question

Hello all..
    I normally use sizeof on variables, but recently foudn out that it can be 
used on a struct name without even having a variable declared as that struct 
type.  for example if I have a struct called StudentType and I wanted to know 
the size of StudentType (without calc'ing by hand)  I would do somthing like 
this:
long studentsize;
StudentType temp;
studentsize = sizeof(temp);
however i recently found out that I can simply do studentsize = 
sizeof(StudentType);  Well at least in Turbo C++ 4.5 one can, I don't know if 
this is standard.
Now my question is, does the compiler treat "sizeof(StructName);" as a 
constant?  During compile time will it lookup the size of the stuct and 
simply use that number instead of calculating the size of the stucture each 
time?
I'm useing Turbo C++ 4.5, and with its limitations I'm guessing no, but I'm 
also wondeing if a 'good' c++ compiler would do it (ie Watcomm, Borland)...
thanks for any info...
-Jamie
... Welcome to hell -- here's your copy of Windows
--- FMail/386 1.02
---------------
* Origin: KastlerocK + Jeannette, PA + 412.527.3749 (1:129/230)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.