Menu

MCPP and getopt

2008-01-10
2013-05-28
  • Dwayne Boone

    Dwayne Boone - 2008-01-10

    Hi,

    I am using the library version of MCPP and my program can make multiple calls mcpp_lib_main() within the same process. I found that when doing this the getopt() calls did not work properly after the first call. The OS I am using is CentOS 4.4 (but I have seen problem on other OS as well).

    After looking into it a bit I found that even though NEED_GETOPT was set by configure and the getopt() function in lib.c was compiled, when getopt() was called from the do_options() method in system.c, it was the OS getopt() that would get called rather than the MCPP getopt().

    I believe the simplest solution (and what I implemented) is to get rid of the NEED_GETOPT check entirely and just always use the getopt() defined in lib.c, no matter what the OS provides. I renamed the function to mcpp_getopt() (and mcpp_optind, etc) to remove any confusion with OS getopt().

    Would it be possible for the next MCPP release to do this?

    Regards,
    Dwayne

     
    • Kiyoshi Matsui

      Kiyoshi Matsui - 2008-01-11

      Thank you very much for the debugging.

      I have just acknowledged the problem using nm command.  On my Linuxes,
      ld links getopt(), optind, opterr and optarg of lib.c, but at the same
      time it links optopt of glibc for some reason!

      Anyway, it will be safe to use always getopt() of lib.c renaming it to
      mcpp_getopt() (and mcpp_optopt, etc.) as your proposal.  I will do it in
      the next revision of SVN.  lib.c will be absorbed into system.c.

      Thanks again!

       

Log in to post a comment.