Re: ptr conversions and values



"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.


.



Relevant Pages

  • Re: ptr conversions and values
    ... > precision complex number can have the same representation as a double. ... > whereas any connection between memory locations and integers is a part ... >> 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. ...
    (comp.std.c)
  • Re: Exact-Point paradox
    ... The phrase "be infinite" has no meaning. ... a mapping from the natural numbers into the reals which is strictly ... More commonly, we model two-dimensional geometry as ordered pairs, ...
    (sci.math)
  • Re: function return pointer of int?
    ... The standard uses "value" to mean different things in ... the meaning is always as defined. ... It produces a value of pointer type. ... then it may be a trap representation, which is not a value of pointer ...
    (comp.lang.c)
  • Re: Does knowledge without reasoning useful
    ... A representation of number with symbols in a computer ... reason about x. ... input has no meaning unless it can be connected to ... giving it meaning (giving it connections), ...
    (comp.ai.philosophy)
  • Re: Conditional as lvalue
    ... Values are defined as the meaning of the contents of an object, ... prove it from the wording of the standard, ... A value can't be stored in an object; only a representation ... talking about the value and reasoning about it as though a ...
    (comp.std.c)