Mail Archives: djgpp/1999/12/01/07:33:10
On Wed, 01 Dec 1999 15:27:16 +1100, Michael Abbott aka frEk
<20014670 AT snetch DOT cpg DOT com DOT au> wrote:
On Wed, 01 Dec 1999 15:27:16 +1100, in comp.os.msdos.djgpp you wrote:
> Heya
>
> Yep, sizeof() is a built in operator...
>
> AFAIK, it's converted straight into a typeless token, ie if it's printf ("%i",
> sizeof(int)); it will be parsed to printf("%i", 4); and then that number will
> be converted to the appropriate type (in this case integer)...
No. It's vice versa. The compiler doesn't care if you wrote "%d" or
"%f" or whatever in your printf format string. It will blindly feed a
value of type size_t and not a "typeless token" (sizeof - although
usually evaluated at compile time - is _not_ a preprocessor
instruction) and it is _your_ task to specify the correct type.
Whenever you are sure that the value fits into an unsigned int then
printf("%u\n", (unsigned)sizeof(mytype) );
is correct and portable to any ANSI compiler. Of course
printf("%d\n", sizeof(mytype) );
usually happens to work, too, with DJGPP.
Regards
Horst
- Raw text -