I
iler.ml
I am writing code that uses two third-party libraries.
They both define same macro OP_ENCRYPT, and
luckily for me, they both define it to 0. (In one include,
it's '#define OP_ENCRYPT 0', in another include it's 0x0).
I cannot change contents of those two includes.
This generates comipler warning 'macro redefined'. It's easy
to suppress the warning with #ifdef. But I want to also
cross-check that those two macros have same value.
I am thinking about this:
#include <first-lib.h> // defines OP_ENCRYPT
#define FIRST_OP_ENCRYPT OP_ENCRYPT //(*1)
#undef OP_ENCRYPT
#include <second-lib.h> // defines OP_ENCRYPT again
#if OP_ENCRYPT != FIRST_OP_ENCRYPT // (*2)
#error definitions mismatch
#endif
The problem here is that he rhs of define (*1) is expanded at line
(*2) which is too late. As a result, this does not really check
two values. The condition will always be true even if one
..h defined OP_ENCRYPT to 0 and other .h defined OP_ENCRYPT to 1.
I cannot change contents of those two includes.
Is there better way to check equality of macros defined in
two different includes without changing the contents of includefiles ?
Thanks
Yakov Lerner
They both define same macro OP_ENCRYPT, and
luckily for me, they both define it to 0. (In one include,
it's '#define OP_ENCRYPT 0', in another include it's 0x0).
I cannot change contents of those two includes.
This generates comipler warning 'macro redefined'. It's easy
to suppress the warning with #ifdef. But I want to also
cross-check that those two macros have same value.
I am thinking about this:
#include <first-lib.h> // defines OP_ENCRYPT
#define FIRST_OP_ENCRYPT OP_ENCRYPT //(*1)
#undef OP_ENCRYPT
#include <second-lib.h> // defines OP_ENCRYPT again
#if OP_ENCRYPT != FIRST_OP_ENCRYPT // (*2)
#error definitions mismatch
#endif
The problem here is that he rhs of define (*1) is expanded at line
(*2) which is too late. As a result, this does not really check
two values. The condition will always be true even if one
..h defined OP_ENCRYPT to 0 and other .h defined OP_ENCRYPT to 1.
I cannot change contents of those two includes.
Is there better way to check equality of macros defined in
two different includes without changing the contents of includefiles ?
Thanks
Yakov Lerner