高级语言的低级功能
我想了解高级语言的一些低级功能。 我可以立即指出: - 按位运算 位字段 - 指针算术 - 内联组装 - 中断功能,
如果您指出一些不在我的列表中的功能,我将不胜感激。如果 C 或 Pascal 拥有它们就好了,但基本上任何高级语言都可以。 谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
C 不支持内联汇编器也不支持中断,所有实现它们的 C 代码都使用非标准编译器扩展。然而,C++ 通过标准支持内联汇编程序。
以下是 C 的一些其他重要的与硬件相关的功能:
函数指针对于 C/C++ 来说是相当独特的,它使得执行位于特定内存地址的代码成为可能,并使得执行其他与硬件相关的任务成为可能。有关函数指针使用的更多详细信息,请参阅此:嵌入式系统中的函数指针< /a>.
整数类型。 C 和 Pascal 都支持不同大小的 int 类型(字节、字、双字等),尽管标准没有指定它们的大小。出于同样的原因,sizeof 运算符也可能很重要。
C 还对内存对齐有一些支持,例如明确说明填充字节应如何表现的规则。
对于硬件相关的编程来说,Volatile关键字也是一个重要的特性,因为它允许变量实时更新,并且不用担心编译器的优化。
const 关键字在硬件相关的编程中用于确定数据将在何处结束:NVM 或 RAM。
C 缺乏的其他重要功能包括作为语言一部分的多线程支持以及内存屏障支持。一些 C 编译器通过 volatile 关键字实现内存屏障,但不能保证它能够按照任何标准工作。
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.
引用维基百科:
C 不是这样的语言,因为它与计算机的细节非常接近。
看看你的列表:
所有这些都与计算机/操作系统架构本身密切相关,被认为不是高级。
Quoting Wikipedia:
C is no such language, as it stays extremely close the the details of the computer.
And looking at your list:
All of those are closely related to the computer/OS architecture itself and are considered not high-level.
Ada 是一种对低级编程提供良好支持的高级语言。
除了前面提到的 C 之外,Ada 还固有地支持并发系统。 任务是一种语言构造,不需要单独的库。对于并发系统,Ada 还提供了所谓的“受保护类型”,它允许在任务之间使用共享变量或数据,而无需额外考虑互斥或信令。基本语言库还提供对中断处理的支持。
对于数据访问,可以通过使用表示子句来定义数据的精确表示。由于强类型化,在不同的数据表示之间定义视图转换也很简单,例如允许在空间和速度之间进行权衡。
还可以通过机器代码插入根据需要直接生成程序集。
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.