I'm using a 3rd party open-source application that does something I think is strange. I'd like to hear your opinion on whether you think this is wrong / evil / an abomination / etc., or if there is some justifiable reason to do this.
Simply put, they use #include pre-proc directives to include "header files" that include fragments of code. Not prototypes of functions. Not in-line functions. Just sections of code.
Here is a simple example. First the main.cpp file:
#include <iostream>
//Other "normal" includes here...
int main(int argc, char *argv[]) {
cout << "Initializing program..." << endl;
#include "parseArgs.h"
// ... remainder of the program
cout << "Exiting." << endl;
return 0;
}
And within the parseArgs.h header file, a small code fragment. Note that this is exactly and only what is in the parseArgs.h file. This is not part of a function. There are no include guards, just the following 4 lines:
argList args(argc, argv);
if(!args.valid()) {
cout << "Invalid arguments.";
exit(1);
}
In the real program, there are several of these #include directives, with each one doing another small task.
It seems dangerous and crazy. I don't know why they don't write and call these as functions.
Your ideas and opinions?