C - 仅标量运算?

发布于 2024-08-22 20:50:42 字数 443 浏览 9 评论 0原文

在维基百科上阅读:

“术语高级和低级本质上是相对的。几十年前,C 语言和类似语言通常被认为是“高级”,因为它支持表达式求值、参数化递归等概念函数、数据类型和结构,而汇编语言被认为是“低级”语言,今天许多程序员可能将 C 称为低级语言,因为它缺乏大型运行时系统(没有垃圾收集等),<。 em>基本上只支持标量操作,并提供直接内存寻址,因此它很容易与汇编语言以及 CPU 和微控制器的机器级别混合。”

http://en.wikipedia.org/wiki/High_level_language

这到底是什么意思?哪些操作是其他编程语言提供而 C 不提供的?

Reading on Wikipedia:

"The terms high-level and low-level are inherently relative. Some decades ago, the C language, and similar languages, was most often considered "high-level", as it supported concepts such as expression evaluation, parameterised recursive functions, and data types and structures, while assembly language was considered "low-level". Many programmers today might refer to C as low-level, as it lacks a large runtime-system (no garbage collection etc), basically supports only scalar operations, and provides direct memory addressing. It therefore readily blends with assembly language and the machine level of CPUs and microcontrollers."

http://en.wikipedia.org/wiki/High_level_language

What does this mean exactly? What operations do other programming languages provide which C does not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

廻憶裏菂餘溫 2024-08-29 20:50:46

鉴于本文的上下文和主题,本文所指的是 C 语言本身定义的术语“标量”。在 C 语言中,算术类型和指针类型一起称为标量类型(参见 6.2.5/21)。在日常语言中,我们经常看到这些类型被称为基本类型或内置类型(而正确的正式术语再次是标量 )。要点是标量类型旨在成为硬件立即(或几乎立即)支持的类型。 C 中的大多数非概念运算仅对标量类型进行操作。

如果您看一下 C 语言的历史,您会发现 C 的早期版本非常严格标量,以至于您甚至无法将一个结构对象分配给另一个结构对象(或传递它到一个函数/从一个函数按值返回)。核心语言中进行结构复制的能力后来被添加到 C 中。直到今天,它本质上仍然是整个核心语言中唯一的非标量操作。

另一方面,C++ 以及其他高级语言支持对用户定义类型(根据定义不是标量)的操作,或者支持对其他类型的操作没有硬件的直接支持。

PS 不,本文试图表达的观点与向量运算无关,与标量运算相反。当然,对向量运算的支持与语言级别完全正交。您可以使用低级语言和高级语言进行向量运算。术语标量在我上面描述的意义上使用。

Given the context and topic of the article, what the article is referring to is the term "scalar" as it is defined in C language itself. In C language arithmetic types and pointer types together are called scalar types (see 6.2.5/21). In everyday language we often see these types referred to as basic types or built-in types (while the proper formal term is, again, scalar). The point is that scalar types are intended to be the types that are immediately (or almost immediately) supported by hardware. Most non-conceptual operations in C operate on scalar types and scalar types only.

If you take a look at the history of C language, you'll see that early versions of C were so restrictively scalar, that you couldn't even assign one struct object to another struct object (or pass it to a function/return from a function by value). The ability do the struct copying in the core language was added to C later. And to this day it remains essentially the only non-scalar operation in the entire core language.

C++, on the other hand, as well as other higher-level languages, supports operations on user-defined types, which are by definition not scalar, or on other types that have no immediate support from hardware.

P.S. No, the point the article is trying to make has nothing to do with vector operations, as opposed to scalar operations. Support for vector operations is, of course, completely orthogonal to the level of the language. You can have vector operations in low-level languages as well as in high-level languages. The term scalar is used in a sense that I described above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文