www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/28/23:07:42

Date: Sun, 28 Apr 1996 21:54:38 -0600 (CST)
From: Aaron Ucko <UCKO AT VAX1 DOT ROCKHURST DOT EDU>
Subject: Re: sizeof(int) == 4?!
To: j DOT aldrich6 AT genie DOT com
Cc: djgpp AT delorie DOT com
Message-id: <01I43939PW4I006NXH@VAX1.ROCKHURST.EDU>
Organization: Rockhurst College; Kansas City, MO
MIME-version: 1.0

>>The use of long has no effect in DJGPP since int's are "long" (32 bit)
>>by default.
>
>Actually, printf() and similar commands will moan and groan if you send
>them longs with %d specifiers, or ints with %ld.  I guess this is for
>compatibility, as no compiler I've seen has required the use of %h
>for shorts.

That is because shorts are promoted to ints when calling undeclared
functions or ones which take variable arguments.  Don't leave the h off
when you call scanf() and relatives, however, or you'll trash two bytes
of innocent memory without even realizing it.  (Because the ix86 family
is little endian, if foo is a pointer to type int then it so happens
that (short) *foo == * (short *)foo.  Don't rely on this, as it will
work only 1/65536th of the time on big-endian machines.)

>Speaking of longs vs. ints, I had a great deal of fun with v1.2, which defined
>size_t as an int rather than a long, which is standard.  Then, when v2 came
>out and turned size_t back to a long, I had to go and change all those
>print specifiers back.  Or was it size_t?  I can't even remember now, but it
>was one of the defined _t types.  :)

If you don't want to worry about this again, just cast explicitly.

-- Aaron Ucko (ucko AT vax1 DOT rockhurst DOT edu; finger for PGP public key) | httyp!
"That's right," he said. "We're philosophers. We think, therefore we am."
-- Terry Pratchett, _Small Gods_ | Geek Code 3.1 [for explanation, finger 
 hayden AT mankato DOT msus DOT edu]: GCS/M/S/C d- s: a18 C++(+++)>++++ UL++>++++ P++ 
 L++>+++++ E- W(-) N++(+) o+ K- w--- O M@ V-(--) PS++(+++) PE- Y(+) PGP(+) t(+)
 !5 X-- R(-) tv-@ b++(+++) DI+ !D-- G++(+++) e->+++++(*) h!>+ r-(--)>+++ y?

- Raw text -


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