In my code base I find that two modules have structures with the same name. It is giving a name conflict error. Is there a way to resolve it without changing the code?
This is a terrible hack, but it would be possible to use a macro to redefine the name of the struct, like so
// a.h
struct collide {
int a;
};
// b.h
struct collide {
float b;
};
// test.c
#define collide a_collide
#include "a.h"
#undef collide
#include "b.h"
int main(){
struct a_collide a;
struct collide b;
return 0;
}
You'd probably want to rename the struct for both headers to give errors when someone inevitably uses the wrong struct, perhaps in a wrapper header like
// wrap_a.h
#define collide a_collide
#include "a.h"
#undef collide
Remember to undef the macro so you don't get random replacements throughout your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With