Re: ptr conversions and values
- From: "Wojtek Lerch" <Wojtek_L@xxxxxxxx>
- Date: Thu, 13 Oct 2005 10:59:23 -0400
"S.Tobias" <siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3r74miFhsd5kU1@xxxxxxxxxxxxxxxxx
> [order of quotes slightly rearranged]
> kuyper@xxxxxxxxxx wrote:
>> S.Tobias wrote:
>>> kuyper@xxxxxxxxxx wrote:
>> ...
>> For two values to be equivalent requires, essentially, that they have
>> the same meaning. Two arithmetic values have the same meaning if
>> they're mathematically equal. Two pointer values are equivalent if they
>> point at the same object. Two character values are equivalent if they
>> represent the same character. Two aggregate values are equivalent if
>> their corresponding elements are equivalent. A pointer value can't have
>> the same meaning as an integer value, so they can't be equivalent.
>
> What I cannot comprehend is how you can accept that a complex type
> and a corresponding array, or an imaginary and a corresponding real,
> can have the "same meaning", and a pointer and an integer can't.
They don't have the same meaning. That's why the standard explicitly
specifies what pairs of values have the same representation:
"Each complex type has the same representation and alignment requirements as
an array type containing exactly two elements of the corresponding real
type; the first element is equal to the real part, and the second element to
the imaginary part, of the complex number."
"Each imaginary type has the same representation and alignment requirements
as the corresponding real type. The value of an object of imaginary type is
the value of the real representation times the imaginary unit."
> [snip]
> How is this "fundamental difference" different from mapping to
> complex types and to corresponding arrays? I don't do anything
> substantially different that the Standard does: I attach additional
> meaning to an integer and treat it as a pointer that points at the
> location of an i'th byte in a char array that occupies the whole
> memory. I couple an integer and a pointer when they "point" at the
> same location. How is it different from what the Standard does:
> it attaches a meaning of a complex number to an array of two reals,
> and joins it with a complex type that expresses the same value.
One important difference is that when the standard says it, it's part of the
standard; when you say it, it's not.
> I agree with all that mostly. Only I still can't understand
> why "pointers are equivalent when they convert into each other"
> should be better than "when they point at the same location".
Because it better covers the case where the location has correct alignment
for one type but not the other. And it doesn't introduce situations where
two values are guaranteed to be equivalent in some sense, but the only way
to produce one from the other is not by a conversion but by reinterpreting
the representation. It would be a bad idea to encourage reinterpreting of
representations as a safer substitute for conversions.
.
- References:
- Re: ptr conversions and values
- From: S.Tobias
- Re: ptr conversions and values
- Prev by Date: Re: Argument of free() should be const void*
- Next by Date: Re: Argument of free() should be const void*
- Previous by thread: Re: ptr conversions and values
- Next by thread: Re: ptr conversions and values
- Index(es):
Relevant Pages
|