0
votes

In the 7.1.3 of the C11 standard are listed some rules about which are the reserved identifiers.

At the end is said:

No other identifiers are reserved. 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.

However, if I try with GCC to break one of those rules, for example I write something like int __A; the compiler tells me nothing. Now maybe I did not understand well, but then which of those rules define the fact that you can have an undefined behavior?

2
@Deduplicator, my question is not what's an UB but if all the rules can generates an UB! - xdevel2000
@xdevel2000, not all, just those which say so. This one says so. The standard should have every part of the language defined (declaring something UB is fine from the point of the standard: it explicitly defines a particular case to be an UB). The point of UB as I see is that it clearly defines in which cases a compiler may do "arbitrary stuff": if on a particular behavior there is no such declaration in the standard, the behavior should be at least deductible. - Jubatian
@Jubatian: No, the standard only explicitly calls out UB in some cases. Where it does not define anything, it is undefined by omission. - Deduplicator
@Deduplicator: well, never tried to get into the depths of a C compiler to experience this, just out of curiosity: could you point me to one or two of such omissions which are particularly interesting / critical? I interpreted these somewhat like "Hey, you, compiler! Here you can do whatever you want, but everywhere else it's no-no for messing around!". - Jubatian

2 Answers

5
votes

A possible outcome of undefined behavior is that you get no warnings, no errors, and everything works fine.

Another outcome is that you upgrade your compiler by a point-release and previously working code starts breaking.

0
votes

The compiler might warn you about undefined behaviour but it doesn't have to. And in many cases it doesn't. For GCC you should at least use the options -Wall -Wextra but it wont help in this case.

A static analysis tool such as splint, PC-Lint, QA-C, etc. will give you much more warnings about undefined behaviour.