Thread: AUTOCONF macro + gcc -Wunreachable-code = NOWORK

  1. #1
    Registered User
    Join Date
    Sep 2005

    AUTOCONF macro + gcc -Wunreachable-code = NOWORK

    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 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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Dunno, but malloc isn't in malloc.h, it's in stdlib.h

    > -Dunreachable-code
    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.

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


    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:
    #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:
          [exit (malloc (0) ? 0 : 1);])],
    and replace it with something like:
          [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, 12:51 PM
  4. Replies: 0
    Last Post: 02-21-2002, 06:05 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM