This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/13945] New: -Wconversion behaviour


[forwarded from http://bugs.debian.org/226952]

Given the code:

#include <stdio.h>

void foo8(unsigned char);

void foo8(unsigned char q)
{
    printf("Quant8: 0x%X\n", q);
}


int main (void)
{
    int i;

    i = 0x12;
    foo8( (unsigned char)i );
    return 0;
}

Compiling it like so:

@ashland [~/tmp] $ gcc -o tst tst.c -Wconversion
tst.c: In function `main':
tst.c:16: warning: passing arg 1 of `foo8' with different width due
to prototype

Despite this being perfectly valid C code!  I guess someone might want
that for some odd reason, however, -Wconversion also does something
useful:

     Also, warn if a negative integer constant expression is
     implicitly converted to an unsigned type.  For example, warn
     about the assignment `x = -1' if `x' is unsigned.  But do not
     warn about explicit casts like `(unsigned) -1'.

This is actually helpful.  It would be nice if gcc could do the above
via a separate -W..... flag and leave:

`-Wconversion'
     Warn if a prototype causes a type conversion that is different
     from what would happen to the same argument in the absence of a
     prototype.  This includes conversions of fixed point to floating
     and vice versa, and conversions changing the width or signedness
     of a fixed point argument except when the same as the default
     promotion.

to whoever needs such an odd warning.

-- 
           Summary: -Wconversion behaviour
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: debian-gcc at lists dot debian dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13945


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]