I know that Binary Literal in C is standardized from C 14.
However, although I fix the std
as c 11
, it works well. Because actually, I expected an error. The following is my code which I expected an error.
int main(){
int a = 0b1010; // an error is expected
std::cout << a << std::endl;
}
Also, I have compiled and executed the above file with the following command.
g -std=c 11 -Wall main.cpp -o runfile
./runfile
What is the reason that an expected result does not come out? Is there something that I've got wrong?
CodePudding user response:
Binary literals have been a compiler extension in GCC long before C 14 standardized them. You can compile with -pedantic
to warn on extensions and -pedantic-errors
to elevate those specific warnings to errors:
<source>:3:11: error: binary constants are a C 14 feature or GCC extension
3 | int a = 0b1010; // an error is expected
| ^~~~~~