commit 6ce5a27db3b55876659f7792e0b752ef1e831000 parent 08765974b090c1c46b4edaf51b1738354aa5c303 Author: vaplv <vaplv@free.fr> Date: Wed, 3 Feb 2016 19:50:03 +0100 Define the __STDC_<LIMIT|CONSTANT>_MACROS in C++ Work around for libc that follows the C99 standard. Diffstat:
| M | src/rsys.h | | | 26 | ++++++++++++++++++++++++++ |
1 file changed, 26 insertions(+), 0 deletions(-)
diff --git a/src/rsys.h b/src/rsys.h @@ -20,7 +20,33 @@ #error "Unsupported compiler" #endif +/* In C99 standard, C++ defines some macros (eg UINT32_MAX) only when + * __STDC_LIMIT_MACROS or __STDC_CONSTANT_MACROS are defined before <stdint.h> + * is included. The C11 standard removes this constraint. The following work + * around always define those macros in C++ so that a C library implementation + * which follows the C99 standard can be used in C++. */ +#ifdef __cplusplus + #ifndef __STDC_LIMIT_MACROS + #define __STDC_LIMIT_MACROS + #define STDC_LIMIT_MACROS_DEFINED_BY_RSYS__ + #endif + #ifndef __STDC_CONSTANT_MACROS + #define __STDC_CONSTANT_MACROS + #define STDC_CONSTANT_MACROS_DEFINED_BY_RSYS__ + #endif +#endif + #include <stdint.h> + +#ifdef STDC_LIMIT_MACROS_DEFINED_BY_RSYS__ + #undef __STDC_LIMIT_MACROS + #undef STDC_LIMIT_MACROS_DEFINED_BY_RSYS__ +#endif +#ifdef STDC_CONSTANT_MACROS_DEFINED_BY_RSYS__ + #undef __STDC_CONSTANT_MACROS + #undef STDC_CONSTANT_MACROS_DEFINED_BY_RSYS__ +#endif + #include <stddef.h> #include <stdlib.h> #include <stdio.h>