Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gcc -Wconversion and function with char argument

14 views
Skip to first unread message

Horst Kraemer

unread,
Feb 8, 1999, 3:00:00 AM2/8/99
to

[ posted and mailed]

On Mon, 08 Feb 1999 14:09:07 +0100, ludovi...@inist.fr (Ludovic
WALLE) wrote:


> When I try to compile the following source file chararg.c:
>
> void f (char c) {}
>
> int main ()
> {
> f ('A');
> }
>
> with the -Wconversion option:
>
> gcc -Wconversion chararg.c
>
> I get the message:
>
> chararg.c: In function `main':
> chararg.c:5: warning: passing arg 1 of `f' with different
> width due to prototype
>
> It seems to happend with any function having a char argument.


Correct. Perhaps you misunderstood the meaning of '-Wconversion'.

-Wconversion warns whenever the declaration

void f (char c);

would lead to a different conversion sequence than the prototype-less
declaration

void f();


If you call f('A') then the argument 'A' has type int.

If f is declared as 'void f(char)' then 'A' will be converted to char
before it is passed to f. If f is declared as 'void f()' then 'A' will
be passed to f "as is", i.e. as an int.

Regards
Horst


0 new messages