Does ansi C place a limit on the number of external variables in a program?

孤者浪人 提交于 2019-12-20 05:15:48

问题


By external variable I mean a variable declared with the extern modifier (and defined elsewhere in the program).

I've been told of this limitation, and couldn't find a confirmation or rebuttal on the web. Is this true? If so, which is the limit? Is it usually enforced by compilers?


回答1:


Yes, there is a minimal limit that every compiler should support.

In this case, every compiler should be able to support at least 4095 external identifiers in one translation unit (but most compilers probably support much more).




回答2:


The C99 standard specifies several translation limits (5.2.4.1). One of those is :

4095 external identifiers in one translation unit

The C89 standard specifies this limit (2.2.4.1) :

511 external identifiers in one translation unit

Note that these are minimum limits for conforming implementations, not absolute limits.




回答3:


My understanding is that the language does not impose a maximum limitation. Compilers and platforms would impose a limit.

Compilers may restict the quantity due to the memory they want to devote to tracking and translating these.

The platform always has limited space for variables.



来源:https://stackoverflow.com/questions/6835718/does-ansi-c-place-a-limit-on-the-number-of-external-variables-in-a-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!