AUTOCONF macro + gcc -Wunreachable-code = NOWORK

This is a discussion on AUTOCONF macro + gcc -Wunreachable-code = NOWORK within the Linux Programming forums, part of the Platform Specific Boards category; hi, sry for the strange subject but i don't know where to ask this (if someone knows a good place ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    4

    AUTOCONF macro + gcc -Wunreachable-code = NOWORK

    hi,
    sry for the strange subject but i don't know where to ask this
    (if someone knows a good place PLZ let me know)

    -i work on gentoo linux on x86 (nothing speciall)

    -in my configure.ac i use AC_FUNC_MALLOC
    to check for a system malloc function that is gnu compilant.
    if i compile with the standard options (i think just -02) it
    works fine:
    ">checking for GNU libc compatible malloc... yes"

    -BUT if i use "-Dunreachable-code -W -Werror"
    ">checking for GNU libc compatible malloc... no"
    so i guess there is sth. strange in malloc.h that make the test
    bail out with the options above. but this is a system header it should
    compile without any warnings RIGHT!?


    PLZ if someone has ever had a prob. like this or knows there to
    post this question. let me know

    thomas zauner

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Dunno, but malloc isn't in malloc.h, it's in stdlib.h

    > -Dunreachable-code
    -W
    -D
    Are you making this up as you go?
    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.

  3. #3
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235

    -Wunreachable-code

    Assuming that you mean "-Wunreachable-code" rather than "-Dunreachable-code", the answer is fairly simple (though hard to track down.)

    The problem is that the configure script is generating something like:
    Code:
    #include <stdlib.h>
    int main()
    {
    exit (malloc (0) ? 0 : 1);
    return 0;
    }
    The combination of "-Werror" and "-Wunreachable-code" to GCC will cause the "return 0" in the generated code to be unreachable (GCC recognizes exit() as not returning), thus produces a warning, which (due to "-Werror") is an error, hence the test fails because the compile fails.

    If you're feeling ambitious, and insist on using the combination of "-Werror" and "-Wunreachable-code", you could go to /usr/lib/share/autoconf/autoconf (or wherever you have the autoconf M4 files), and edit the file autoconf.m4f; search for the line that reads:
    Code:
          [exit (malloc (0) ? 0 : 1);])],
    and replace it with something like:
    Code:
          [if (malloc(0) == 0) exit(1);])],
    This should provide an execution path to the "return 0;", thus get rid of the unreachable-code warning, which should then produce the correct result. Test it, of course, as I may have screwed the code fragment up. This only fixes this instance of unreachable code in autoconf's generated tests, so my recommendation is that you don't use "-Wunreachable-code" in distributed apps, just in development.

    I hope this helps.
    Last edited by filker0; 10-11-2005 at 11:54 AM. Reason: Fix the code fragment

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. << !! Posting Code? Read this First !! >>
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 10-03-2002, 03:04 PM
  2. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  3. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 11:51 AM
  4. Replies: 0
    Last Post: 02-21-2002, 05:05 PM
  5. Replies: 4
    Last Post: 01-15-2002, 11:04 PM

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