Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many variables can be in local scope

My question is pretty simple: how many variables can be in local scope to be properly translated?

I have to create a small translator (for studying purposes) from C++ to Assembly. During the translation process, there is a dynamic table of identifiers (variable names, in simple case, I suppose). How many can there be?

I mean, my table is dynamic anyway as well, but I need to create an array of tokens where each has 2 numbers - a table ID and a record ID in the table. So I want to know, which type should these IDs be - int, short, long, etc?

like image 888
Notrum666 Avatar asked Feb 23 '21 16:02

Notrum666


People also ask

Which variables have local scope?

A local variable, however, has a limited scope: it exists only within the block that it is declared in. Once that block ends, the variable is destroyed and its values lost . A local variable of the same name declared elsewhere is a different variable.

How many variable scope are there in?

PHP has three different variable scopes: local. global.

What are the 3 three places of scope variables?

A scope is a region of the program and broadly speaking there are three places, where variables can be declared: Inside a function or a block which is called local variables, In the definition of function parameters which is called formal parameters.

How many variable scopes are there in C?

There are four types of scope: file scope, block scope, function scope and.


1 Answers

How many variables can be in local scope

The C++ standard does not specify an exact maximum number.

It does have following recommendation (quote from latest standard draft):

[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].

Someone wrote a test for this, and commonly used compilers appear to support at least 8k: https://github.com/fritzone/cpp-stresstest

like image 70
eerorika Avatar answered Oct 16 '22 15:10

eerorika