delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/22/02:25:46

Date: Mon, 22 Sep 1997 09:24:40 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Brett Porter <bporter AT rabble DOT uow DOT edu DOT au>
cc: DJGPP <djgpp AT delorie DOT com>
Subject: Re: %d
In-Reply-To: <199709220431.OAA28739@rabble.uow.edu.au>
Message-ID: <Pine.SUN.3.91.970922091803.11436B-100000@is>
MIME-Version: 1.0

On Mon, 22 Sep 1997, Brett Porter wrote:

> Just a BTW, does anyone know whether %d looks for a 32-bit int or a 16-bit
> int in djgpp?

int is 32-bit in DJGPP, so %d looks for a 32-bit int.

> I originally thought it would take a 32-bit, but I notice that
> there is a long modifier %l, but no short modifier.

That's for the same reason that there's only one %f format for printing
both floats and doubles: ANSI C requires that all shorts are promoted to
ints when passed to functions with variable argument lists.  So, even if
you pass a short, `printf' gets an int, and doesn't need a special format
for shorts. 

> I haven't had any problems yet, but if I pass it a 16-bit short and it
> expects a 32-bit and then I try and pass it some more arguments I may (in
> the future) get a crash, so I thought I'd check it out now.

Relax, you will *never* get a crash with `printf' because of this.

In fact, altough ANSI C permits it, I'd advise against declaring *any* 
functions (even with constant argument lists) with shorts or floats as 
one of the arguments; I suggest to always use ints and doubles instead.

- Raw text -


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