Comment by burfog
7 years ago
A systems programming language can run on bare hardware by itself, or nearly so. It is acceptable to require a very small amount of assembly code, for example to implement something like memcpy or bcopy, or to provide atomic operations.
A language is disqualified if it requires an OS or if it requires code written in a different non-assembly language. Cheating, by adding that as a huge (impractical) amount of assembly, also disqualifies a language.
Funny story about gcc: The compiler demands a memcpy, which it sometimes uses for struct assignment. If you implement memcpy in the normal way, gcc will helpfully replace your implementation with a call to memcpy! Despite this, C is still a systems programming language.
> It is acceptable to require a very small amount of assembly code, for example to implement something like memcpy or bcopy, or to provide atomic operations.
There is some stuff missing in your list: preparing the stack pointer, address layout, etc. You also need tools to produce text and data sections that can be loaded at a specific address. Even if C is a low level language, there is still quite some stuff between it and the "bare hardware". In that sense, the only language that gives you enough control to produce the binary exactly in the form needed by the hardware (without relying on external tools or libraries) is assembly.
> You also need tools to produce text and data sections that can be loaded at a specific address.
Though, of course, most compilers provide extensions that make this task generally possible within C (using the loose definition of "I don't need any separate files or inline assembly, just attributes and flags).
So we're getting closer to it. The linker inputs and scripts are the only "real" systems programming language.
stack pointer is an implementation detail. The standard does not mention the word stack even once.
So then C is cheating by your definition, because it is impossible to implement ANSI C standard library without using Assembly or compiler extensions.
I did say a small amount of assembly was fine. By "cheating", I mean something like converting the perl interpreter to assembly code and claiming that perl thus doesn't require code written in some other language.
Leaving out libraries is normal for a systems programming language. It is fine unless the language entirely doesn't work without the libraries.
that's what -ffreestanding and others (-nostdlib) are for.
C is not cheating, the compiler assumes you work on user level stuff. Want to write bare metal (kernel) then you need to tell the compiler.
Right, as mentioned on my comment, compiler extensions.
Strictly speaking that isn't proper C as defined by ISO/IEC 9899:2018.