New warning in gcc-4.0

This is a discussion on New warning in gcc-4.0 within the C Programming forums, part of the General Programming Boards category; I just upgraded to gcc-4.0 and found that it generates a new warning: Code: itsme@itsme:~/C$ cat signed.c void func(unsigned char ...

  1. #1
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163

    New warning in gcc-4.0

    I just upgraded to gcc-4.0 and found that it generates a new warning:
    Code:
    itsme@itsme:~/C$ cat signed.c
    void func(unsigned char *str)
    {
    }
    
    int main(void)
    {
      char str[] = "hi";
    
      func(str);
    
      return 0;
    }
    itsme@itsme:~/C$ gcc -Wall signed.c
    signed.c: In function 'main':
    signed.c:9: warning: pointer targets in passing argument 1 of 'func' differ in signedness
    itsme@itsme:~/C$
    I wasn't even aware that doing that was a bad thing. Is it covered anywhere in the C standard? It also throws a fit if you do something like:
    Code:
    itsme@itsme:~/C$ cat signed2.c
    int main(void)
    {
      unsigned int *ptr;
      int i = 5;
    
      ptr = &i;
    
      return 0;
    }
    itsme@itsme:~/C$ gcc -Wall signed2.c -o signed2
    signed2.c: In function 'main':
    signed2.c:6: warning: pointer targets in assignment differ in signedness
    itsme@itsme:~/C$
    This is causing a whole lot of warnings to show up in all sorts of code that used to compile cleanly for me. I don't think this was a documented change either. Does anyone have any information on this that I might have missed? It just seems really annoying to me. You can't even disable the warning. You don't need to compile with -Wall for the warning to be generated.
    If you understand what you're doing, you're not learning anything.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,538
    Code:
    -funsigned-char'
         Let the type `char' be unsigned, like `unsigned char'.
    
         Each kind of machine has a default for what `char' should be.  It
         is either like `unsigned char' by default or like `signed char' by
         default.
    char (by itself) is either unsigned or signed, but that in itself is implementation-specific.
    Try with the above flag (there's also -fsigned-char) to make it clear what sign your unadorned char type is.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21