Thread: New warning in gcc-4.0

  1. #1
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA

    New warning in gcc-4.0

    I just upgraded to gcc-4.0 and found that it generates a new warning:
    itsme@itsme:~/C$ cat signed.c
    void func(unsigned char *str)
    int main(void)
      char str[] = "hi";
      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
    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:
    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
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
         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
    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.

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, 01: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