Is it possible to define a macro in a C file, and then change behavior of another C file using this definition?
For instance, suppose we have a file named b.c:
#include <stdio.h>
#define ABC
void function() {
printf("b.c\n");
}
And another file named a.c:
#include <stdio.h>
int main() {
#ifdef ABC
printf("b.c defined this\n");
#endif
printf("a.c\n");
}
These files are compiled together. I want the definition of ABC in b.c to influence a.c.
I know I was supposed to be using a header file, but I don’t want to do that. Is there another way to achieve this?
In my scenario, b.c is a sort of sub-application that will complement the behavior of a.c, and it should also be able to override behavior in there.
Is there an alternative to macros that can achieve this?
Use global variables or use callbacks. The “best” solution depends on precisely how much flexibility you need.