I'm studying the coreutils source codes to get better in programming and I found these lines in base64.c and in others:
while ((opt = getopt_long (argc, argv, "diw:", long_options, NULL)) != -1)
switch (opt)
{
// ... other stuff
case_GETOPT_HELP_CHAR; // <- this especially
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
// .. other stuff again
I didn't know what the heck this means, until I found this one in system.h :
#define case_GETOPT_HELP_CHAR \
case GETOPT_HELP_CHAR: \
usage (EXIT_SUCCESS); \
break;
I didn't know that you can actually make Macros that consists of so many statements! Isn't it risky to use so many statements in Macros or is this a good coding-style I should learn?
EDIT: Also I noticed there are actually alot of MACROS used in coreutils. It confuses me a little bit, because I come from a C++ background.
#define STREQ(a, b) (strcmp (a, b) == 0)
For example this one above, is it really necessary? It makes reading the code harder and there is not much saved by just doing STREQ in an inf statement
EDIT2: On the other hand, I like this one very much, thanks to Jay:
#define COMMAND(NAME) { #NAME, NAME ## _command }
struct command commands[] =
{
COMMAND (quit),
COMMAND (help),
...
};