I have the following problem. I'm writing C code that is dependent on someone else's code, which I am not able to make changes to. And in that code (that I'm not allowed to change) is a define preprocessor directive. My code is compiled before this other piece of code. And I need a way to circumvent this, so that my code is not affected by this define directive.
Is there a way to somehow tell the preprocessor to ignore all directives from now on?
What almost worked for me was the following pragma poison directive, but this unfortunately throws an error. Is there a way to suppress this error?
#pragma GCC poison define
I know that this is not an easy question to answer, but I'll really appreciate some help.
I think that you can do something like this: Assume that the problem is that the other code define
string
aschar *
and somewhere in the headers you need to include. You can define in yourc
files after the includes from the other code just:If your code include every times the same headers you can put all includes in one header and sanitize it at end: An example could be
other_include.h
:If you are not so lucky you must create a
sanitize.h
header and include it after all other include in yourc
files.Moreover If you need some portion of code where disable the macro and recover it after :
and when you want recover it
That not really elegant but you can use it as a fine grain to make your subroutine safe.