3 ms·
They discuss this in section 3.2 of the paper. The C99 standard (in section 6.3.2.3) says that integers can be cast to pointers, but, except in the special case
by _delirium 11y ago
They discuss this in section 3.2 of the paper. The C99 standard (in section 6.3.2.3) says that integers can be cast to pointers, but, except in the special case of the integer 0, "the result is implementation-defined, might not be correctly aligned, might not point to an entity of the referenced type, and might be a trap representation". This implementation chooses the last option: if you cast an integer to a pointer, you get a pointer as a result, but one that you can't successfully dereference.
- c99throwa2 11y agoOf course I read that, or else I would have no idea they broke pointer round-tripping. I believe this violates C99 §7.18.1.4 (if the TruffleC language defines the uintptr_t type in stdint.h): The following type designates an unsigned integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer: uintptr_t If the TruffleC language does not define uintptr_t ("these types are optional"), then hey, that's fine. A lot of valid code won't compile, though.
- mike_hearn 11y agoIs uintptr_t widely used? I don't recall ever seeing it before.
- david-given 11y agoIt's really useful if you want a type to which you can cast any (non-float) primitive value and know that you can cast it back to the same value you had before. I've used it as the cell type for a Forth interpreter, for example (where cells have to be able to represent addresses as well as integers). It's probably particularly not useful for general applications programming.