Hacker News new | ask | show | jobs
by yjftsjthsd-h 883 days ago
> C requires an OS to provide CRT and syscalls for it to function.

That doesn't make sense; the OS itself is written in C.

> If you were to write freestanding C code, this certainly changes. At which point the memory model becomes "what you decide to provide".

Okay, so we're back to, C doesn't impose anything on you, though the OS may.

2 comments

The C memory model is what imposes pointer provenance and all that jazz on C programs. The OS provides an abstraction over physical memory, and programming languages abstract over individual address spaces.
> That doesn't make sense; the OS itself is written in C.

Please point to a non-userspace memory allocation library/implementation that does not rely on lower level logic to function.

> Okay, so we're back to, C doesn't impose anything on you, though the OS may.

You're just reversing the original statement.

The statement was "you can't assume anything about memory in C" (paraphrasing). They then asked "why not?"

The explanation is that:

What you think is 'memory' in C isn't, and certainly doesn't map to what most people assume about memory; because C doesn't impose a memory model, it relies on the underlying OS/environment to do so. The only "memory model" is thus: a requested allocation (whether on the stack or heap), if provided to you, will match your request; all other assumptions are invalid.

If you want to move goalposts, argue about logical boundaries, etc, have at it. Or if that answer doesn't satisfy you, I don't know what to tell you; but simply rephrasing the original problem does even less.