TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: KURT KUZBA
from: DARIN MCBRIDE
date: 1997-11-02 10:00:00
subject: sizeof() question

JK>   Now my question is, does the compiler treat
JK>   "sizeof(StructName);" as a constant?  During compile time
JK>   will it look up the size of the stuct and simply use that
JK>   number instead of calculating the size of the stucture
JK>   each time?
 KK>    Why don't you write a little program to test the time it
 KK>    takes to find sizeof(int) and compare the results to
 KK>    finding sizeof(MyStruct)?
 KK>    It should add sizeof(MyStruct) to a table of values and the
 KK>    lookup time should be equal if it does not calculate it on
 KK>    every call.
 KK>    My tests seem to indicate that they take the same ammount
 KK>    of time.
In this case, you'd want to check the assembly code produced.  In there, 
you'd find that sizeof() was being replaced by a constant.
--- Maximus/2 3.01
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)

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™.