(Richard Bos) writes:
> wrote:
>> Richard Bos <> wrote:
>> >
>> > Address _could_ be a reason, but I cannot find anything in the Standard
>> > which demands that different functions have addresses that compare
>> > differently. Nor, for that matter, can I find an explicit, blanket
>> > demand that all objects' addresses must differ.
>>
>> 6.5.9p6:
>>
>> Two pointers compare equal if and only if both are null
>> pointers, both are pointers to the same object (including a
>> pointer to an object and a subobject at its beginning) or
>> function...
>>
>> Different objects are not "the same object", nor are different functions
>> "the same function".
>
> That has not stopped implementation writers from equalising pointers to
> string literals. In the source code, these are definitely different
> objects, but since a program can only discover the difference by
> invoking undefined behaviour, they are allowed to be "the same object"
> for pointer purposes. Unless you're telling us that this _very_ common
> optimisation is illegal, I don't see why the same thing should not be
> allowed for functions for which the same proviso holds.
There are no objects in my source code; objects exist only during
program execution.
The object in question is the "array of static storage duration"
mentioned in C99 6.4.5p5. The standard explicitly allows two string
literals to refer to the same object in C99 6.4.5p6:
It is unspecified whether these arrays are distinct provided their
elements have the appropriate values. If the program attempts to
modify such an array, the behavior is undefined.
As for memcpy and memmove possibly having the same address, I can
imagine a program storing the address of a standard function and later
making some decision based on which standard function the address
points to. I have difficulty imagining *good* code doing something
like this, but it isn't the standard's job to impose good coding
practices.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"