Strange warning about passing argument with different width due to prototype with gcc 4.4.0 on 64 bits machine

Axel Freyn axel-freyn@gmx.de
Tue Aug 24 14:18:00 GMT 2010


Hi,
On Tue, Aug 24, 2010 at 03:28:17PM +0200, José Luis García Pallero wrote:
> El día 24 de agosto de 2010 14:49, Tiago Maluta
> <tiago.maluta@gmail.com> escribió:
> > 2010/8/24 José Luis García Pallero <jgpallero@gmail.com>:
> >
> >>
> >> Can someone reproduce the behaviour?
> >>
> >
> > I reproduced your behavior. Running your test case with gcc 4.3.1 on
> > Gentoo all goes fine, but with gcc 4.2.1 on MacOSX the warning shows
> > up.
> 
> I didn't remember that I have MacOSX 10.4 installed in my iBook G4.
> The gcc installed is 4.0.1. And as Tiago, the warning shows up. But
> only the warning concerning the char input argument. But in my
> workstation Xeon 64 bits tha warning appears for char arguments and
> for the long argument without explicit cast.
I would propose to also compare sizeof(int), sizeof(char) and
sizeof(long) for those platforms (e.g. using
printf("%ld\n",sizeof(char));
)

In principle, the warning only claims that the function prototype did
influence the way how gcc calls the function:
 - whenever a function without a prototype is called, the C standard
   claims that all integral arguments (like char, int, long) are
   converted to "int" -- and passed as "int" arguments to the function
 - in your examples, you have function prototypes, specifying that those
   arguments shall be passed as "char" or as "long"
The warning tells, that gcc is doing that -- and thus everything should
work fine.
However, on a machine where sizeof(int)=sizeof(long) (like e.g. many
i386 processors have "sizeof(int)=sizeof(long)=4"), int and long have
the same width and such no warning appears. 
On x64, I think the most common values are "sizeof(int)=4" and
"sizeof(long)=8", such that here it's a difference and the warning
appears for long.

I don't know what's the width of char, int and long on ppc, but maybe
that explains the effects?

On the other hand: I don't know whether new versions of gcc continue to
emit this warning at all?

Axel



More information about the Gcc-help mailing list