Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS mean?

Tags:

c++

macros

stl

I see this in the standard C++ libraries for my system, as well as some of the headers in a library I'm using.

What are the semantics of these two definitions? Is there a good reference for #defines like this other than the source itself?

like image 242
Matthew Willis Avatar asked Jun 12 '09 12:06

Matthew Willis


2 Answers

__STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS are a workaround to allow C++ programs to use stdint.h macros specified in the C99 standard that aren't in the C++ standard. The macros, such as UINT8_MAX, INT64_MIN, and INT32_C() may be defined already in C++ applications in other ways. To allow the user to decide if they want the macros defined as C99 does, many implementations require that __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS be defined before stdint.h is included.

This isn't part of the C++ standard, but it has been adopted by more than one implementation.

like image 57
Dingo Avatar answered Oct 12 '22 23:10

Dingo


The above issue has vanished. C99 is an old standard, so this has been explicitly overruled in the C++11 standard, and as a consequence C11 has removed this rule.

More details there:

  • https://sourceware.org/bugzilla/show_bug.cgi?id=15366
like image 43
malat Avatar answered Oct 12 '22 23:10

malat