Gnu C 编译器 (gcc) 允许标签作为语言扩展的值: http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html 但是文档说:
如果我们使用这种机制跳转到不同函数中的代码,那么完全 不可预测的事情会发生。 我们对类c语言有什么限制?
最佳答案
限制不仅(仅)在 GCC 中,而且在 C 标准本身中。
A label name is the only kind of identifier that has function scope. It can be used (in a goto statement) anywhere in the function in which it appears, and is declared implicitly by its syntactic appearance (followed by a : and a statement).
(来自 N1548,§6.2.1.3)。
拥有“标签变量”不会改变不同函数(例如堆栈)中的环境完全不同的事实(并且与单个函数内部不同,预测它是不可能的);跳来跳去几乎会破坏一切。
堆栈问题更准确地说:目标函数中局部函数变量的值是未知的,函数参数是未知的,目标函数一结束就不知道程序应该从哪里继续等等。 (而且堆栈不是唯一的问题)
关于c++ - Gnu 编译器限制是否适用于 C 语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33205809/