Hi,
I have a software that has 2 versions of an implemented algorithm, so it used different versions of the same class (in my case its SSE vs AVX, but really, it's not relevant) in 2 different compiler units, and suprisingly the linker take the initiative of taking an arbitrary one.
Is it a bug (that I reproduced as well in Microsoft and GCC compiler) or a feature (if that so can someone help me finding where this behavior is specified) ?
Here is how to reproduce the problem:
toto.h
#include <stdio.h> #ifdef FLAG class foo { public: void bar() { printf("FLAG\n"); } }; #else class foo { public: void bar() { printf("NO FLAG\n"); } }; #endif #ifdef FLAG void call_foobar_FLAG() #else void call_foobar_NOFLAG() #endif { foo().bar(); }
toto_flag.cpp
#define FLAG #include "toto.h"
toto_noflag.cpp
#include "toto.h"
main.cpp
void call_foobar_FLAG();
void call_foobar_NOFLAG();
int main(int argc, char ** argv)
{
call_foobar_FLAG();
call_foobar_NOFLAG();
}
We should expect as output
FLAG NO FLAG
But we get
FLAG FLAG
or
NO FLAG NO FLAG
depending in which order object are linked...