I’m trying to compile a code depends on ROOT, Geant4 and others on Windows with MSVC, which works fine on Linux with gcc and clang. I noticed that in ROOT/RConfig.h, at line 395 there is a #define introduces __x86_64__ which “by default” do not appear on Windows:
But I’m also working around with G4. In CLHEP/Random/MixMaxRng.h, there are:
CLHEP/Random/MixMaxRng.h:
166 | #if defined(__x86_64__)
167 | myuint_t mod128(__uint128_t s);
168 | myuint_t fmodmulM61(myuint_t cum, myuint_t a, myuint_t b);
169 | #else // on all other platforms, including 32-bit linux, PPC and PPC64, ARM and all Windows
These lines of code is protected by #if defined(__x86_64__). Obviously, this is to avoid involving __uint128_t that does not exist on Windows. However, through the cooperation with ROOT/RConfig.h, this code is exposed and causes compilation error C2061: syntax error: identifier '__uint128_t' because __uint128_t is not defined.
I understand that it may be more convenient to introduce __x86_64__ on windows, but it does cause some problems. There is a way to solve the error I mentioned here, like globlally #define __uint128_t to some other things, but it just not perfect, and I am not sure whether this __x86_64__ will lead to more potential problems. Is there any better solutions? Or should this be considered a defect in ROOT or CLHEP? Could this lead to more potential problems?
welcome to the ROOT forum and thank you for the report.
So if I understand correctly:
ROOT defines __x86_64__ for Windows, as it’s not defined there
CLHEP assumes that if __x86_64__ is defined, then we are definitely not running on windows so we can use other stuff that’s not defined on Windows such as __uint128_t
On one hand ROOT defining such generic macros on Windows is tricky, on the other CLHEP could check for “are we on windows” more directly or could check for “is _uint128_t defined” as well.
Thanks for your reply! Yes, that’s exactly what I mean. I agree with @Axel that it seems unsafe to define __x86_64__ for windows inside ROOT, since __x86_64__ actually belongs to other platforms.
It is constructive to introduce some ROOT dialects, such as R__x86_64__ as proposed.
Thanks,
ZhaoSH
P.S. If we regard this as an issue of ROOT, do I need to report it elsewhere?
Thanks for the reply! In fact, I am testing the cross-platform compatibility of a project, it’s interdependence inside is a little bit complex. Although the inclusion order of each file is correct (G4/CLHEP is included before any ROOT), not all files includes these two headers I mentioned at once, so there is no guarantee for the inclusion order of those two. However, the approach you proposed is certainly useful when there is only a single file, for example, ROOT macros.
I see 166 occurrences of __x86_64__ in 61 files in ROOT. I probably did define that on Windows 64 to avoid having yet another #define. Anyway, I’ll fix that