6 years, 10 months ago.

How to detect MBED vs __linux__ or __FreeBSD__

Hi everyone,

So I'm working on the uTensor project and we want it to compile against any platform, mbed, Linux, etc. Right now we are running into issues with Big/Little Endian conversions:

https://stackoverflow.com/questions/809902/64-bit-ntohl-in-c which can roughly be handled with the following preprocessor code

#if defined(__linux__)
#  include <endian.h>
#elif defined(__FreeBSD__) || defined(__NetBSD__)
#  include <sys/endian.h>
#elif defined(__OpenBSD__)
#  include <sys/types.h>
#  define be16toh(x) betoh16(x)
#  define be32toh(x) betoh32(x)
#  define be64toh(x) betoh64(x)
#endif

Pretty much I am looking to hide https://github.com/uTensor/uTensor/blob/master/uTensor_util.hpp#L61-L66 around a platform specific ifdef.

What's the easiest way of doing this? And what would the preprocessor command be?

Thanks! -Michael

Be the first to answer this question.