DeVault: Announcing the Hare programming language
DeVault: Announcing the Hare programming language
Posted May 10, 2022 18:36 UTC (Tue) by farnz (subscriber, #17727)In reply to: DeVault: Announcing the Hare programming language by Vipketsh
Parent article: DeVault: Announcing the Hare programming language
If I promise that the function calls are just naming what code does, but it's real behaviour is poking global volatile pointers, and those functions are implemented in pure C89, there's no difference in behaviour. Given the following C definitions of get_zeroed_page, get_ptr_to_handle and release_page, you still have the non-determinism, albeit I've introduced a platform dependency:
const size_t PAGE_SIZE;
struct pt_entry {
volatile char *v_addr;
volatile char *p_addr;
}
volatile struct pt_entry *pte; // Initialized by outside code, with suitable guarantees on v_addr for the compiler implementation and on p_addr
int *page_location = pte->v_addr;
void *get_zeroed_page() {
pte->p_addr += PAGE_SIZE;
memset(pte->v_addr, 0, PAGE_SIZE);
return pte->v_addr;
}
void release_page(void *handle) {
assert(handle == pte->v_addr);
pte->p_addr -= PAGE_SIZE;
}
void *get_ptr_to_handle(void* handle) {
assert(handle == pte->v_addr);
return page_location;
}
This has semantics on the real machine, because of the use of volatile - the writes to *pte are guaranteed to occur in program order. But the compiler does not have any way to know that volatile int *v_addr ends up with the same value between two separate calls to get_ptr_to_handle but points to different memory.
Also, I'd note that C89 does not have language asserting what you claim - it actually says quite the opposite, that the compiler does not have to assume that *ptr1 has changed within the C abstract machine, since ptr1 is not volatile. It's just that early implementations made that assumption because to do otherwise would require them to analyse not just the function at hand, but also other functions, to determine if *ptr1 could change. Like khim, you're picking up on a limitation of 1980s and early 1990s compilers, and assuming it's part of the language as defined, and not merely an implementation detail.
