I'm practicing reading others' code, picked up one of the simplest package in the GNU core-utils, GNU yes. coreutils-8.26 to be specific, because my machine is debian stretch. Code direct links are at the end.
In main(), we have this line:
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
usage, AUTHORS, (char const *) NULL);
PROGRAM_NAME
, PACKAGE_NAME
, Version
, AUTHORS
shall just be some #define
macro for constant c-string, thus we indeed passed 8 parameters to parse_long_options
here.
In long-options.h
which we included, we declared parse_long_options
as following, which accepts only 6 arguments:
void parse_long_options (int _argc,
char **_argv,
const char *_command_name,
const char *_package,
const char *_version,
void (*_usage) (int),
/* const char *author1, ...*/ ...);
So, my question is, how does this package, GNU yes, actually compile and run? It's an UB, at least in C99. (1) Is it just because how GCC is implemented, and hence shall be avoided?
code direct links:
yes.c from coreutils-8.26: (2)
long-options.c from coreutils-8.26: (3)
long-options.h from coreutils-8.26: (4)
ftp of GNU: (5)