2 ms·
Why not extend the language with an "rmem" keyword or function that you use like this: rmem(pointer) and you're guaranteed to produce a memory read, rather than
by anon4 11y ago
Why not extend the language with an "rmem" keyword or function that you use like this: rmem(pointer) and you're guaranteed to produce a memory read, rather than reusing a value in register. Then say that the compiler is free to assume two pointers/arrays etc. never overlap. Then, introduce linters which can detect most cases of these-two-pointers-might-overlap. Maybe runtime ones like valgrind.
I want to write C as high level assembly. If I put values in registers and reuse them, then I'm opening myself for the same kind of problems as if I'm writing C and not doing explicit memory reads.
- pcwalton 11y agoYou have to allow pointers and arrays to overlap. Just to name one of tons of examples, you couldn't write the callback compar(a, b) to qsort() without it: the two pointers a and b are part of the same array and therefore a[1] might legally alias b[0], for example. There is something to controlling aliasing, though. It basically leads you to Rust's (or ISO Core C++ with lifetime profile) memory model. :)