I just compiled NIST RS274NGC G-Code Interpreter and saw unbelievable 890 warnings from gcc.
200 of them were caused by this array:
char * _rs274ngc_errors[] = {
/* 0 */ "No error",
/* 1 */ "No error",
/* 2 */ "No error",
/* 3 */ "No error",
/* 4 */ "A file is already open", // rs274ngc_open
<...>
which, according to my basic understanding, should be const char *
.
Then I saw these macros (they actually appear several times in different .cc files):
#define AND &&
#define IS ==
#define ISNT !=
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define NOT !
#define OR ||
#define SET_TO =
Then I saw a lot of warnings suggest braces around empty body in an 'else' statement [-Wempty-body]
caused by really strange control flow altering macros like this (yes, with dangling else!):
#define PRINT0(control) if (1) \
{fprintf(_outfile, "%5d \n", _line_number++); \
print_nc_line_number(); \
fprintf(_outfile, control); \
} else
Report suggests that
A.5 Interpreter Bugs
The Interpreter has no known bugs
All of that makes me wonder - why is it written so strangely? I can understand macros like PRINT0 - error handling in C can be a real pain - but why would anyone use SET_TO
instead of =
?
I can believe that all this code was generated but couldn't it be generated in warning-free way?
I'm not an expert in any way, I'm just really curious.