linux-mips
[Top] [All Lists]

Re: load/store address overflow on binutils 2.14

To: Geert Uytterhoeven <geert@linux-m68k.org>
Subject: Re: load/store address overflow on binutils 2.14
From: Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de>
Date: Tue, 12 Aug 2003 01:16:35 +0200
Cc: Chip Coldwell <coldwell@frank.harvard.edu>, Linux/MIPS Development <linux-mips@linux-mips.org>
In-reply-to: <Pine.GSO.4.21.0308112257180.20421-100000@vervain.sonytel.be>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <20030810145425.GE22977@rembrandt.csv.ica.uni-stuttgart.de> <Pine.GSO.4.21.0308112257180.20421-100000@vervain.sonytel.be>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.5.4i
Geert Uytterhoeven wrote:
[snip]
> > > Strangely, this is actually "correct" behavior.  Arguments on
> > > variable-length argument lists are implicitly "promoted" to unsigned
> > > int at the widest.  See K&R 2nd ed. A6.1 and A7.3.2.
> > 
> > Ugh. Thanks for pointing this out. I wasn't aware of it.
> > 
> >     printf("%016Lx\n", ~a);
> > 
> > Produces the expected output. So it is actually an implementation
> > bug in binutils, which isn't fixable for 2.14 and earlier, because
> > those have to remain at K&R C level. The K&R requirement was only
> > recenly loosened.
> 
> How can it print the correct output if ~a is `promoted' to unsigned int, while
> you specify %Lx in the format string?

From 'info gcc':

Double-Word Integers
====================

   ISO C99 supports data types for integers that are at least 64 bits
wide, and as an extension GCC supports them in C89 mode and in C++.
[...]
   There may be pitfalls when you use `long long' types for function
arguments, unless you declare function prototypes.  If a function
expects type `int' for its argument, and you pass a value of type `long
long int', confusion will result because the caller and the subroutine
will disagree about the number of bytes for the argument.  Likewise, if
the function expects `long long int' and you pass `int'.  The best way
to avoid such problems is to use prototypes.


Thiemo

<Prev in Thread] Current Thread [Next in Thread>