Pure, Nothrow in Generic Programming

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Nov 27 15:34:04 PST 2009


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



More information about the Digitalmars-d mailing list