#include in middle of code
c, header
Solution
At compile time you can have bit control of conditional inclusion of a header file
#ifdef MAGIC
#include "matrix.h"
#else
#include "grid.h"
#endif
at compile time
gcc -D MAGIC=1 file.c
or
gcc file.c
But at run-time conditional inclusion of a header file is not possible.
It means what your pseudo code is showing is not possible.
Problem
I would like to make a conditional inclusion of a header file in my program. Is it possible and, if yes, how do I do it? My idea is to do something like this: ``` switch(opt) { case 0: { #include "matrix.h" break; } case 1: { #include "grid.h" break; } } ``` That is how VS did it when I wrote it. Is it right?