News for hackers. Stuff that matters.
Re:Examining ARM vs. x86 Memory Models with Rust by kibwen on Saturday June 27, 2020 @01:35AM (#23659750)
C programmers use "contents" to refer to the address of the pointer? As a non-C programmer, asking what is "contained" in the pointer would certainly refer to the pointee.
Re:Examining ARM vs. x86 Memory Models with Rust by wahern on Saturday June 27, 2020 @02:32AM (#23659943)
In C a pointer is an object in its own right, so referring to the contents of a pointer, p, means the same thing as referring to the contents of an integer, i; namely, the value held by the object. A pointer value has semantic meaning and usefulness the same as an integer value, completely divorced from the machine representation, which in a pure C program should always be irrelevant for pointer and arithmetic types alike.

I don't think I can articulate well why it's important to keep in mind and appreciate value semantics. Certainly many C programmers, especially the newer ones, are far too concerned with value representation rather than the abstract value itself, often conflating the two. I guess one good example of why it's important to understand pointers as proper objects with abstract values is when working with pointers-to-pointers, pointers-to-pointers-to-pointers, etc. Pointer arithmetic is another case, which doesn't overlap with the former as much as you'd think. In these cases understanding pointers as values is important to understanding the semantics of a program, and more generally how to leverage the language efficiently and safely. Note that these semantics have no analog in references, the construct in, e.g., C++. It doesn't make sense to conceptualize references as independent objects; rather, a reference is a syntactic construct, no more an object than a list initializer.

Yeah, as a C programmer I would find it kind of odd if someone seemed to conceptually elide the character of pointers as proper first-class objects.

Re:Examining ARM vs. x86 Memory Models with Rust by kibwen on Saturday June 27, 2020 @02:54AM (#23660004)
I wonder if pointer arithmetic specifically is the sticking point here; when using pointers in other languages I don't ever do pointer arithmetic on them, so the integral value of the pointer is easily ignored.

For those wondering, given the context of Rust here, both references and C-style pointers are first-class in Rust, but references (which are overwhelmingly more common) don't directly permit pointer arithmetic at all, and would require one to first cast the pointer to an integer.

Re:Examining ARM vs. x86 Memory Models with Rust by userbinator on Saturday June 27, 2020 @01:44AM (#23659786)
C and Asm at least... and "address of the pointer" is something entirely different. For example (assuming a 16-bit system and radix 16 for brevity),

    Name:    Address:    Value:
    p        0100        02 01
    v        0102        12 59
p is the pointer. The address of p is 0100. The contents of p are the two bytes which form the address of v, 0102. The contents of v are the two bytes which form the value 5912.

I wonder if this confusion of the pointee with the pointer is what makes this concept seem so difficult to those who didn't start with Asm (especially multiple indirections) --- I certainly saw a lot of that when I used to teach CS courses.

Re:Examining ARM vs. x86 Memory Models with Rust by bregma on Saturday June 27, 2020 @07:48AM (#23661202)
> I wonder if this confusion of the pointee with the pointer is what makes this concept seem so difficult to those who didn't start with Asm

Possibly (I started with asm, so I can't speak with certainty) but it could also be because many modern programmers first learned Java or JavaScript or Python in which most names are references to object (thus effectively all variables are addresses). Their first languages do not have value semantics, so grasping the concept of value semantics applied to a reference itself (ie pointers) is a major stretch.

Re:Examining ARM vs. x86 Memory Models with Rust by ptx on Saturday June 27, 2020 @12:57PM (#23662954)
In Python, everything is a pointer to a PyObject and always passed by value, so thinking of them as values makes sense. You can even easily get the address of the pointer by calling id on it (but not as easily convert it back).
Re:Examining ARM vs. x86 Memory Models with Rust by gpderetta on Saturday June 27, 2020 @08:38PM (#23665876)
doesn't id return the address of the pointee?
Re:Examining ARM vs. x86 Memory Models with Rust by ptx on Sunday June 28, 2020 @04:10AM (#23667403)
Ah, yes - the value of the pointer, which is an address, the address of the pointee. (Even after reading that other thread, I messed up my terminology.)

Actually, id returns a pointer to a PyObject representing an integer, the value of which is the value of the pointer that was passed as an argument, which is the address of the pointee. Right?

Re:Examining ARM vs. x86 Memory Models with Rust by nicoburns on Saturday June 27, 2020 @10:12AM (#23661939)
JavaScript does have value semantics for booleans and numbers. But it doesn't have any reference types which allow you to inspect the reference as a value.
Re:Examining ARM vs. x86 Memory Models with Rust by jfkebwjsbx on Saturday June 27, 2020 @02:40AM (#23659970)
A pointer does not contain what it points to, it just points to it.

The content (the value) of a pointer is an address.