|
|
|
|
|
by _kst_
1033 days ago
|
|
Step 1: Define just what "portable assembly" actually means. An assembly program specifies a sequence of CPU instructions. You can't do that in a higher-level language. Perhaps you could define a C-like language with a more straightforward abstract machine. What would such a language say about the behavior of integer overflow, or dereferencing a null pointer, or writing outside the bounds of an array object? You could resolve some of those things by adding mandatory run-time checks, but then you have a language that's at a higher level than C. |
|
Whatever the CPU does. Eg, on x86, twos complement.
> or dereferencing a null pointer
Whatever the CPU does. Eg, on X86/Linux in userspace, it segfaults 100% predictably.
> or writing outside the bounds of an array object?
Whatever the CPU does. Eg, on X86/Linux, write to whatever is next in memory, or segfault.
> You could resolve some of those things by adding mandatory run-time checks, but then you have a language that's at a higher level than C.
No checks needed. Since we're talking about "portable assembly", we're talking about translating to assembly in the most direct manner possible. So dereferencing a NULL pointer literally reads from address 0x0.