I am having trouble writing this macro. I am using ceedling.
I have a file, "globals.h", which has the following code:
#ifndef globals
#ifndef UNITY
#define STATIC static
#else
#define STATIC
#endif
#define globals 1
#endif
So, what should happen here is that any method which uses STATIC will be static if the code is not being tested with unity, else it will be not static.
My test file includes "unity.h", and then includes "globals.h", and then includes "protocol.h".
The file being tested, "protocol.c", includes "globals.h" and then "protocol.h".
The test file, "test_protocol.c", includes "unity.h", then "globals.h", then "protocol.h".
From my understanding, UNITY should be defined first, then it will go to globals.h
, and define STATIC as nothing, since UNITY has been defined already in UNITY.h
However, the behavior I am seeing is that no matter what I do, I cannot get globals.h
to enter that #else
directive, and so it appears to be impossible to have STATIC
be defined as anything other than static
.
However, I know that what i am trying to accomplish is possible, because many people recommend this strategy and have implemented it. So, what am I doing that is causing globals.h
to think that UNITY is not defined, when it is?