mercredi 5 août 2015

Undefine macro defined twice


I want to use a macro defined in different header files with the same name and different implementations. I have two header files h1.h and h2.h. In the first header file I defined:

#define PRINT  printf(" hi , macro 1\n"); 

and in the second header file

#define PRINT  printf(" hi , macro 2\n");

in main() when I try to use PRINT it is printed depending on the order of inclusion. I found some similar problems and they used a wrapper, by including the first header file then defining an inline method:

inline void print1() {
      PRINT();
}

and then undefining PRINT and including the second header file. In main() when I call print1() and PRINT I got the output from them both. My missing point is how after we have undefined the PRINT from the first header file we are still able to have it - in other words what happens when we call it inside the inline function? Did the compiler copy the value of PRINT and assign it to the function and save the function in some way?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire