贴一个我的SVN commit message...

from <getopt.h> in gnu c lib
{{{


struct option
{
  const char name;
  /
has_arg can’t be an enum because some compilers complain about
     type mismatches in all the code that assumes it is an int.  /
  int has_arg;
  int *flag;
  int val;
};

/ Names for the values of the has_arg' field ofstruct option’.  */

# define no_argument        0

define required_argument  1

define optional_argument  2

#endif  /* need getopt */
}}}

Thank you, genius…
–This line, and those below, will be ignored–

起因其实很简单…我在程序里加入了很久以前libg++里提供的一个C++版的GetOpt实现,恰好这个实现里面的一些命名跟GNU C的getopt版本有些类似,然后就发现老是编译不通过……找原因,最后发现是一个第三方库间接包含了GNU C 库里的getopt.h,然后就发现了上面这一段…

不求甚解的库程序员真可怕…

解决方案:

 

$ svn diff

Index: GetOpt.cc

@@ -72,16 +72,16 @@ o[k++] = p->val;

    switch( p-&gt;has_arg ) {
  • case GetOptLongOption::no_argument:
  • case GetOptLongOption::NO_ARGUMENT: { break; }
  • case GetOptLongOption::required_argument:
  • case GetOptLongOption::REQUIRED_ARGUMENT: { o[k++] = ‘:‘; break; }
  • case GetOptLongOption::optional_argument:
  • case GetOptLongOption::OPTIONAL_ARGUMENT: { o[k++] = ‘:‘; o[k++] = ‘:‘; Index: GetOpt.h ===================================================================

@@ -35,7 +35,7 @@ #ifdef GNUG #pragma interface #endif -#define GetOpt_h +#define GetOpt_h 1

/// Describe the long-named options requested by the application. // @@ -57,13 +57,13 @@ /// enum Arg { /// If the option does not take an argument, - no_argument, + NO_ARGUMENT,

 /// If the option requires an argument,
  • required_argument,
  • REQUIRED_ARGUMENT,

    /// If the option takes an optional argument.

  • optional_argument,

  • OPTIONAL_ARGUMENT, };

///

本文网址:http://blog.perlfect.me/2011/11/23/thank-you-genius-gnu-c-programmer.html

comments powered by Disqus