www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/01/07:33:10

From: horst DOT kraemer AT t-online DOT de (Horst Kraemer)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: sizeof() but nothing to do with sizeof( some_structure )
Date: Wed, 01 Dec 1999 09:10:39 GMT
Organization: T-Online
Lines: 34
Message-ID: <3844e46e.232977830@news.btx.dtag.de>
References: <38447026 DOT 1C29B562 AT id-base DOT com> <003e01bf3ba4$acd9e660$0100a8c0 AT pcpablo> <3844A3A3 DOT 29827E2E AT snetch DOT cpg DOT com DOT au>
Mime-Version: 1.0
X-Trace: news02.btx.dtag.de 944039412 17385 0306239354-0001 991201 09:10:12
X-Complaints-To: abuse AT t-online DOT de
X-Sender: 0306239354-0001 AT t-dialin DOT net
X-Newsreader: Forte Free Agent 1.11/32.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019