Groovy hepcat Jamie Kowinsky jived with All on 29 Oct 97 14:26:14!
sizeof() question's a cool scene. Dig it!
JK> I normally use sizeof on variables, but recently foudn out that it
JK> can be used on a struct name without even having a variable declared
JK> sizeof(StudentType); Well at least in Turbo C++ 4.5 one can, I don't
JK> know if this is standard.
Yes, it is standard. Any data type may be measured this way. Types
are measured by enclosing the type in parentheses, while objects can
be measured with or without parentheses. For example:
int i, *ptr;
i = sizeof i; /* valid */
i = sizeof(i); /* valid */
i = sizeof(int); /* valid */
i = sizeof *ptr; /* also valid and equivalent to the above */
i = sizeof int; /* not valid - syntax error */
JK> Now my question is, does the compiler treat "sizeof(StructName);" as a
JK> constant? During compile time will it lookup the size of the stuct
Yes, it is treated as a contant.
Wolvaen
... Al is normal, the _WORLD_ is weird!
--- Blue Wave/RA v2.20
---------------
* Origin: The Gate, Melbourne Australia, +61-3-9809-5097 33.6k (3:633/159)
|