Reputation: 5265
I tried to get __STDC_VERSION__
with gcc 4.8 and clang, but it just not defined.
Compiler flags:
g++ -std=c++11 -O0 -Wall -Wextra -pedantic -pthread main.cpp && ./a.out
http://coliru.stacked-crooked.com/a/b650c0f2cb87f26d
#include <iostream>
#include <string>
int main()
{
std::cout << __STDC_VERSION__ << std::endl;
}
As result:
main.cpp:6:18: error: '__STDC_VERSION__' was not declared in this scope
I have to include some header, or add compiler flags?
Upvotes: 5
Views: 8541
Reputation: 2185
For those who come across the following warning:
warning: "__STDC_VERSION__" is not defined
This is due to the -Wundef
flag which is enabled:
-Wundef
Warn if an undefined identifier is evaluated in an #if directive. Such identifiers are replaced with zero.
(from official GCC documentation)
So you can just define __STDC_VERSION__
to zero (-D__STDC_VERSION__=0
) to suppress these warnings.
Upvotes: 2
Reputation: 33192
The official documentation states:
__STDC_VERSION__
...
This macro is not defined if the -traditional-cpp option is used, nor when compiling C++ or Objective-C.
Also, the C++ standard(s) leave it up to the implementation to define this macro or not, and g++ opted for the latter.
Depending on what you're trying to do the __cplusplus
macro might be an alternative (it is not just defined, it has a value, too ;)
Upvotes: 5