4 ms·
#4 is not completely true, as the "standard" ifdefs are defined by the compiler, not the platform. Thus, they may differ when building on Windows using MSVC and
by rumcajz 12y ago
#4 is not completely true, as the "standard" ifdefs are defined by the compiler, not the platform. Thus, they may differ when building on Windows using MSVC and building on Windows usign MinGW.
- justincormack 12y agoKind of falls out of his using one compiler per platform. There tend to be few differences though unless you use something less standard (like ARM's C compiler).
- brianwski 12y agoOriginal author here. Yeah, my goal was cross platform APPLICATIONS where the first step is choosing your tools. I suppose if you are writing a library like OpenSSL that you want to compile with every last flavor of every last compiler the problem gets worse. I stand by my guideline for applications. Another way to think about it is if you want, use all your own custom compiler flags, then if you can manage to get your compiler flags set by a creative combination of BUILT IN compiler flags, that way your code will compile right out of the box correctly on all platforms. What I dislike is that out of the box the code compiles on zero platforms. Instead, you run a "configurator" program that sets all the cross platform flags correctly. If at all possible, write your code so that it self configures correctly with zero changes on all compilers and all platforms. Please notice the "if at all possible". I think if you are relatively careful and just use basic types this can be done easily. Is it really that amazingly hard to find a native "int32" and "int64" type using ifdefs on every platform/compiler?
- TheLoneWolfling 12y agoWorse come to worse, you include a header file that errors out if anything but one and only one of the platform flags is set, with an error message of something along the lines of "you are using a compiler that does not automatically set the correct flag for this operating system. Please set exactly one of the following flags: ..."
- to3m 12y ago_WIN32 used to be defined for Xbox - it probably still is for Xbox360 and XboxOne too... - as well as Win32/Win64. All very different systems. Cue hilarity! You really, truly are best off making your own defines. (If you absolutely don't want to specify them in the build setup, you can usually autodetect many of your own defines by checking for _WIN32 and _M_IX86 and _MSC_VER and __GNUG__ and so on. Then there's at least only one place to get the logic wrong.)