Question

Is it mandatory that compilers keep the behavior consistent between versions of what the C or C++ standard describes as implementation-defined behavior?

For example the result of some bitwise operations on signed integers must be the same in gcc 4.6 and say in gcc 4.8?

Was it helpful?

Solution

It does not have to be consistent, it just needs to be documented, the draft C99 standard section 3 Terms, definitions, and symbols defines it like so:

implementation-defined behavior

unspecified behavior where each implementation documents how the choice is made

For example the gcc docs has a section C Implementation-defined behavior.

The C++ draft standard also has a similar definition and in section 1.9 Program execution paragraph 2 says:

Certain aspects and operations of the abstract machine are described in this International Standard as implementation-defined (for example, sizeof(int)). These constitute the parameters of the abstract machine. Each implementation shall include documentation describing its characteristics and behavior in these respects.6[...]

OTHER TIPS

No.

The C standard mandates some things. For the ones which are implementation-defined, it does not mandate that you are consistent between versions.

This would not be very useful anyway - what stops you to create "Extra Gcc" instead of "gcc 5"? Who determines what version is actually an upgrade from a previous one?

Implementation defined means that the compiler writer chooses what happens, and that is just it. There's nothing stopping you from changing your mind and do it another way of you want. Nothing forces you to be consistent among different versions of the same compiler.

From the standpoint of the C standard, two versions of the "same" compiler are two different implementations. (Well, it's likely that the earlier is known not to be a C implementation at all due to known conformance errors, and the latter is also likely not to be a C implementation due to unknown conformance errors...) In general, implementors will provide their own guarantees that implementation-defined behavior will remain the same between versions, however. This is because they have already defined the behavior, and if they change it, they're creating an explicit incompatibility with something they already documented as behavior you could rely upon with their product.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top