c++11 - Using char16_t, char32_t etc without C++ 11? -


i have fixed width types including character types. <stdint.h> provides types integers, not characters, unless when using c++11, can't do.

is there clean way define these types (char16_t, char32_t, etc) without conflicting defined c++11 in case source ever mixed c++11 ?

thank :)

checking whether types supported platform-dependent thing, think. example, gcc defines: __char16_type__ , __char32_type__ if these types provided (requires either iso c11 or c++ 11 support).

however, cannot check presence directly, because fundamental types, not macros:

in c++, char16_t , char32_t fundamental types (and header not define such macros in c++).

however, check c++ 11 support. according bjarne stroustrup's page:

__cplusplus

in c++11 macro __cplusplus set value differs (is greater than) current 199711l.

so, basically, do:

#if __cplusplus > 199711l // has c++ 11, can assume presence of `char16_t` , `char32_t` #else // no c++ 11 support, define our own #endif 

how define own?

-> msvc, icc on windows: use platform-specific types, supported in vs .net 2003 , newer:

typedef __int16 int16_t; typedef unsigned __int16 uint16_t; typedef __int32 int32_t; typedef unsigned __int32 uint32_t; 

-> gcc, mingw, icc on linux: these have full c99 support, use types <cstdint> , don't typedef own (you may want check version or compiler-specific macro).

and then:

typedef int16_t char16_t; typedef uint16_t uchar16_t; typedef int32_t char32_t; typedef uint32_t uchar32_t; 

how check compiler in use? use this great page ('compilers' section).


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -