by Arelius · 14y ago · 0 comments
Do yourself a favor, either write clean, portable, clear and concise C code, or use a real pre-processor. The only time you should be using pre processor magic anyways is in a large project that's not a library anyways. So at that point it's pretty trivial to just use a proper pre-processor.
Both of those are actually rather simple macros doing what seems like a mess with pointers. The difference is subtle, but most strongly expressed in that the complexity is innate to the problem, and does not require mucking much with what is entirely weird macro behavior.
#include <iostream>
#include <boost/integer.hpp>
int main()
{
// Notice these signed types are going into unsigned types!
boost::uint64_t i = -9151314442815602945;
std::cout << i << std::endl;
unsigned int j = -327681234;
std::cout << j << std::endl;
return 0;
} port-linux.c
port-win32.c
port-solaris.c
myprog.c
and just compile/link port-$TARGET.c into your program. The code tends to be cleaner, and the platform knowledge is concentrated in one place.