Walter Bright wrote:
Andrei Alexandrescu wrote:
b) incorrect addresses within the application, erroneous result returned

I think it would be implementation-defined behavior - in case (b) memcmp would return an implementation-defined value but still defined.

How could it?

The value itself does not matter. The point is the behavior is not undefined.

Undefined behavior = anything within the realm of physical possibility could happen.

Implementation-defined behavior = the behavior depends on the implementation.

In the memcmp case, the behavior is always defined to return an int or to never return (segfault). The value of the int for incorrect inputs is implementation dependent because it depends on the way data of various objects is laid out in memory. The fact that the definition is complex does not render it undefined.

Let's not confuse undefined with implementation-defined. I am firmly convinced that memcmp never falls in the undefined behavior realm. The behavior is always defined.


Andrei

Reply via email to