Low level capabilities of high level languages [closed]
I would like to know some low-level capabilities of high-level languages. Off the top of my head I could point out: -bitwise operations -bit fields -pointer arithmetic -inline assembly -interrupt functions
I would apreciate if you pointed out some, that aren't in my list. It would be nice if C or Pascal had them, but basically any high-level language will do. Thank you.
C does not support inline assembler nor interrupts, all C code implementing them is using non-standard compiler extensions. C++ however, has support for inline assembler through the standard.
Here are some other important, hardware-related features of C:
Function pointers are rather unique for C/C++ and makes it possible to execute code located at a specific memory address, and makes it possible to perform other hardware-related tasks. See this for more details of function pointer uses: Function pointers in embedded systems.
The integer types. Both C and Pascal support int types of different sizes (byte, word, double word etc), although their sizes are not specified by the standards. For the same reason, the sizeof operator may be important as well.
C also has some support for memory alignment, for example explicitly stating rules for how padding bytes should behave.
The volatile keyword is also an important feature for hardware-related programming, as it allows variables to be updated in realtime, and without worries about compiler optimizations.
The const keyword is used in hardware-related programming to determine where the data will end up: NVM or RAM.
Other important features that C lacks are multi-threading support as part of the language, and memory barrier support. Some C compilers implement memory barriers through the volatile keyword, but there are no guarantees for it to work by any standard.
Quoting Wikipedia:
A high-level programming language is a programming language with strong abstraction from the details of the computer.
C is no such language, as it stays extremely close the the details of the computer.
And looking at your list:
- bitwise operations
- bit fields
- pointer arithmetic
- inline assembly
- interrupt functions
All of those are closely related to the computer/OS architecture itself and are considered not high-level.
One high-level language with very good support for low-level programming is Ada.
In addition to previously mentioned C, Ada has also intrinsic support for concurrent systems. Tasks are a language construct, and do not need separate libraries. For concurrent systems, Ada also provides so called protected types, which allows usage of shared variables or data between tasks without additional consideration of mutual exclusion or signalling. The basic language libraries also provide support for interrupt handling.
For data access, the exact representation of data can be defined by the use of representation clauses. As a result of strong typing, it is also trivial to define view conversions between different representations of data, allowing for example tradeoffs between space and speed.
It is also possible to directly generate assembly as needed, by machine code insertions.
精彩评论