1

I'm writing some serialization code, and obiously, this code needs to know if the result should be big or little endian, so I tried declaring an enum like this:

namespace TerrainGenerator
{
    ...
    enum Endianess {LITTLE_ENDIAN, BIG_ENDIAN};
    ...
}

But for some reason, my IntelliSense was telling me that these values are already declared.

Running g++ also gave me errors, telling me they had been defined as 1234 and 4321 (for little and big endian respectively).

I noticed the errors went away when I stopped including <string>.

Is there somewhere I can find a list of constants that have been declared in the std. libs?

I'm running Arch Linux, Kernel 4.12.8-2-ARCH.

Running strings /usr/lib/libstdc++.so.6 | grep LIBCXX returns a bunch of lines, the highest version number being GLIBCXX_3.4.24.

Running ldconfig -p | grep stdc++ returns:

libstdc++.so.6 (libc6,x86-64) => /usr/lib/libstdc++.so.6
libstdc++.so (libc6,x86-64) => /usr/lib/libstdc++.so

(as suggested by https://stackoverflow.com/a/10355215/6242052 to find what version of the std. libs i'm using)

EDIT: If these values are #defined, on a scale of 1-10 how bad of an idea would it be to #undef them after including all headers? (And possibly re-#define-ing them after my code)

shmoo6000
  • 495
  • 4
  • 22
  • Big Endian and Little Endian are not part of the C++ standard. It is a configuration issue of your compiler. Check your compiler documentation. I know that the setting differs between ARM compiler and Visual Studio. – Thomas Matthews Aug 24 '17 at 17:05
  • 1
    This: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html seems to indicate it should be _ _ ORDER_BIG_ENDIAN _ _ (without the spaces) instead of just straight up BIG_ENDIAN (My g++ version is `g++ (GCC) 7.1.1 20170630`) – shmoo6000 Aug 24 '17 at 17:07
  • Looks like the macros come from [this](http://mirror.fsf.org/pmon2000/2.x/src/sys/sys/endian.h) file. – Rakete1111 Aug 24 '17 at 17:08
  • Is there something I can do besides just renaming my constants? (I've used CAPITAL_UNDERSCORES troughout my entire project (for constants and enums), so for consistency, I'd like to keep the name) – shmoo6000 Aug 24 '17 at 17:12
  • 3
    How about `enum class Endianess {LITTLE, BIG};`? – HolyBlackCat Aug 24 '17 at 17:27
  • Regarding "how bad an idea" - I'd say 1 (as in very bad). Unless your headers are LAST, and NONE your headers EVER INCLUDES ANYTHING, or if it does, it ONLY INCLUDEs YOUR INCLUDEs which NEVER include ANYTHING other than YOUR code - AND YOU CAN GUARANTEE THAT FOREVER AND EVER, then you probably can get away with it. :-D You have no control over what other libraries include, whether system or 3rd party. You could stick in your code some `#ifdef LITTLE_ENDIAN#error someone is including endian.h#endif` to at least determine any violations. But then how do you fix it? – franji1 Aug 24 '17 at 17:59
  • Yeah, I figured it'd be a bad idea, still, thanks for your help everyone! – shmoo6000 Aug 24 '17 at 18:34

0 Answers0