1

I found somewhere that i could detect C++11 using the following line :

#if __cplusplus <= 199711L

I'm using this to conditionally defined fixed-width types such as int32_t or uchar16_t, etc...

The problem is that when using the android NDK, __cplusplus is defined as 1. Is there a more portable way to detect C++11 and the presence of stdint.h to avoid redefinitions ?

Thank you.

Virus721
  • 8,061
  • 12
  • 67
  • 123
  • You should not have to detect `stdint.h`. It should always be available because its IEEE Std 1003.1/Posix. The only header I recall having trouble with is ``. Something I needed was in it rather than ``, so I needed to conditionally include `` based on `#ifdef __ANDROID__`. – jww Jun 09 '15 at 02:38
  • Here is the short way to solve it

    http://stackoverflow.com/a/36324758/4242341

    – Aqua Mar 31 '16 at 05:59

1 Answers1

1

For me it always works:

$ CXX=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++
$ $CXX -x c++ -E -dM /dev/null | grep __cplusplus
#define __cplusplus 199711L
$ $CXX -x c++ -std=c++11 -E -dM /dev/null | grep __cplusplus
#define __cplusplus 201103L

The same for LLVM toolchain:

$ CXX="$NDK/toolchains/llvm-3.5/prebuilt/darwin-x86_64/bin/clang++ -target armv7-none-linux-androideabi"
$ $CXX -x c++ -E -dM /dev/null | grep __cplusplus
#define __cplusplus 199711L
$ $CXX -x c++ -std=c++11 -E -dM /dev/null | grep __cplusplus
#define __cplusplus 201103L

I've tried it with NDK r10d and r10e, and it works in both of them, so there is definitely something wrong with your setup. I could say more if you'd provide minimal project where such problem exist.

Dmitry Moskalchuk
  • 1,249
  • 8
  • 12
  • Thanks for your help. I've decided to create a custom define to indicate whether i want things to be defined or not. – Virus721 Jun 08 '15 at 15:06