If I could find a way to do something similar to this, I could cut out hundreds of lines of code in my application, and dramatically increase maintainability. Anyone have any ideas?
#include <stdio.h>
int main( )
{
#define include_all_files(root) \
#include #root "1.h" \
#include #root "2.h" \
#include #root "3.h" \
#include #root "4.h"
include_all_files( first_library )
include_all_files( second_library )
include_all_files( third_library )
return 0;
}
EDIT:
I appreciate the responses, my example seems to be causing a misdirection in effort, so here is the problem I am actually trying to solve:
I am implementing a finite state machine. Through naming conventions, I have gotten it to be as simple to add a state as:
STATE(initial_screen)
#include "initial_screen.state"
END_STATE
STATE(login)
#include "login.state"
END_STATE
However, if I could answer the original question, I could refactor this down to something as simple as:
ADD_STATE(initial_screen)
ADD_STATE(login)
This is because the file name and the state name, and all the underlying wiring and everything else all follow similar conventions. However, I cannot figure out how to implement the include file based on the token received in a macro.