What do __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS mean?
Asked Answered
S

4

36

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?

Stanton answered 12/6, 2009 at 12:41 Comment(0)
C
51

__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.

Cryology answered 12/6, 2009 at 13:16 Comment(2)
That strikes me as a dangerous naming precedent. It complicates the life of the standardizers - do they have to pay attention to what implementations have done with their namespace.Licence
does not apply to C11 anymore and thus C++11.Ferocity
F
8

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:

Ferocity answered 23/10, 2014 at 8:16 Comment(0)
H
4

In stdint.h under C++, they control whether to define macros like INT32_MAX or INT32_C(v). See your platform's stdint.h for additional information.

Heyward answered 12/6, 2009 at 13:6 Comment(0)
S
-6

The macros are not part of the C++ standard and are probably used for internal purposes in your C++ implementation. If you want to know more about them, you should ask a question with atag that indicates what that implementation is.

Stibine answered 12/6, 2009 at 12:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.