Saturday, 27 May 2017

c - Why is _Generic keyword supported in c99 or c90 modes?

I wrote a simple C program to test the availability of _Generic keyword.



int main() {
int _Generic;
}



I ran the program with gcc-5.3.1 and clang-3.8.0 compilers on Ubuntu.



Obviously this program generated an error when compiled in the latest c11 standard.



But, when compiled with -std=c90 and -std=c99 flags, it generated an error as well. Whereas, the _Generic keyword was only introduced in c11 standard.



Is it that the -std= flags behave differently? And is there a way to test the pure c90 and c99 standards?



EDIT:




I did run the same program with other identifiers which are not keywords as per c11 standard. Like:



int _Hello;
int _Gener;


And they compiled successfully without any errors or warnings.
This is probably because of 7.1.3, which says





If the program declares or defines an identifier in a
context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved
identifier as a macro name, the behavior is undefined




as said by @Art and @Lundin.

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...