gpt4 book ai didi

c++ - 局部范围内可以有多少个变量

转载 作者:行者123 更新时间:2023-12-03 15:41:12 28 4
gpt4 key购买 nike

我的问题很简单:有多少变量可以在本地范围内正确翻译?
我必须创建一个从 C++ 到汇编的小型翻译器(用于学习目的)。在翻译过程中,有一个动态的标识符表(我想是变量名,在简单的情况下)。可以有多少?
我的意思是,无论如何我的表也是动态的,但我需要创建一个 token 数组,其中每个都有 2 个数字 - 表中的一个表 ID 和一个记录 ID。所以我想知道,这些ID应该是哪种类型 - int , short , long , 等等?

最佳答案

How many variables can be in local scope


C++ 标准没有指定确切的最大数量。
它确实有以下建议(引自最新标准草案):

[implimits]

Because computers are finite, C++ implementations are inevitably limited in the size of the programs they can successfully process.Every implementation shall document those limitations where known.This documentation may cite fixed limits where they exist, say how to compute variable limits as a function of available resources, or say that fixed limits do not exist or are unknown.

The limits may constrain quantities that include those described below or others.The bracketed number following each quantity is recommended as the minimum for that quantity.However, these quantities are only guidelines and do not determine compliance.

  • Identifiers with block scope declared in one block ([basic.scope.block]) [1'024].

有人为此写了一个测试,常用的编译器似乎至少支持8k: https://github.com/fritzone/cpp-stresstest

关于c++ - 局部范围内可以有多少个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66337100/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com