News for hackers. Stuff that matters.
Re:“C is quirky, flawed, and an enormous success” – Dennis R... by jstimpfle on Sunday July 09, 2023 @02:12PM (#36657179)
Does the C machine model in fact consist of a single linearly addressable memory space? I think the spec mostly talks about "objects" that are linearly addressable -- not about the whole "memory" (there might not even be such a thing). Technically you aren't even allowed to compare two pointers other than for equality (relational comparisons are possible only within the same array). Just making up pointers is probably already a stretch of the spec, although you'll see lots of that in e.g. embedded projects.

(Disclaimer: I really don't know all the details of the C standards, am not a language lawyer but know enough about the language to feel quite productive in it. Please fill me in or correct me where I'm wrong).

Re:“C is quirky, flawed, and an enormous success” – Dennis R... by kevin_thibedeau on Sunday July 09, 2023 @04:11PM (#36658395)
People will abuse [u]intptr_t to compare addresses from different objects. There is no guarantee that the integer value stored in such variables is representative of a linear memory space and you're supposed to treat them as opaque data but most platforms permit such comparisons. All you're permitted to do is cast a pointer into those types and cast it back to the original type.