语言是否指定了堆栈

语言是否指定了堆栈

本文介绍了C 语言是否指定了堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C 语言定义是否需要堆栈的存在?不支持堆栈的架构呢?这是否意味着这样的架构不能实现定义的 C 语言?

Does the C language definition require the existence of a stack? What about architectures that don't support stacks? Does that mean that such architectures can't implement the C language as it is defined?

堆呢?

推荐答案

没有

C11 标准 不包含词stack,也不包含heap这个词.这意味着它不需要任何名称.

The C11 standard does not contain the word stack, nor does it contain the word heap. That means it does not require either by name.

如果一个架构没有堆栈,它仍然必须有一种机制允许被调用的函数为其变量分配空间,即使它被递归调用.只要 CPU 允许编译器编写者以某种方式实现这样的系统,CPU 就可以支持 C.堆栈是一种处理每个函数变量分配的简单方法,但它远不是唯一可能的机制.

If an architecture doesn't have a stack, it must still have a mechanism to allow a called function to allocate space for its variables, even if it is called recursively. As long as the CPU permits the compiler writer to implement such a system somehow, the CPU can support C. A stack is an easy way to handle per-function variable allocation, but it is far from being the only possible mechanism.

如果您使用的是托管实现(而不是独立实现),则该实现需要通过 malloc()free() 支持动态内存分配代码>和朋友.这通常是通过在堆"上使用空间来完成的,但标准没有规定它必须如何发生,只是必须针对平台进行适当的管理.

If you're in a hosted implementation (as opposed to a freestanding implementation), then the implementation is required to support dynamic memory allocation via malloc(), free() and friends. That is normally done by using space on 'the heap', but the standard doesn't stipulate how it must happen, only that it must be managed appropriately for the platform.

许多看起来很奇怪的标准规则正是为了让不寻常的 CPU 架构能够运行标准 C.

A lot of the standard's rules that seem bizarre are there precisely to make it possible for unusual CPU architectures to run standard C.

这篇关于C 语言是否指定了堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:26