g ++变量名有长度限制吗? [英] is there a length limit on g++ variable names?
问题描述
和一些填充文字
处理最小正文的要求
p>我希望你现在可以快乐地度过任意限制
简答:
没有
长答案:
是,它必须足够小以至于能适应记忆,否则不适用。如果有内在的限制(我不相信有),它是如此巨大,你真的很难达到它。
#! / usr / bin / env python2.6
import sys;
cppcode =
#include< iostream>
#include< cstdlib>
int main(int argc,char * argv [])
{
int%s = 0;
return 0;
}
def longvarname(n):
str =x;
for xrange(n):
str = str +0;
return str;
def printcpp(n):
print cppcode%longvarname(n);
if __name __ ==__ main__:
if len(sys.argv)== 2:
printcpp(int(sys.argv [1]));
使用所需的长度变量名称生成C ++代码。使用以下内容:
./gencpp.py 1048576> main.cpp
g ++ main.cpp -o main
上面的代码没有问题(变量名的长度大约为1MB)。我尝试了一个技巧,但是我并没有对字符串构造这么聪明,所以我决定在gencpp.py花费太长时间时放弃。
无论如何,我非常怀疑gcc预先为变量名分配1MB。它纯粹以记忆为界。
see title
and some filler text
to deal with the requirement of minimum body text
i hope you're happy now arbitrary limits
Short Answer:
No
Long Answer:
Yes, it has to be small enough that it will fit in memory, but otherwise no, not really. If there is a builtin limit (I don't believe there is) it is so huge you'd be really hard-pressed to reach it.
Actually, you got me really curious, so I created the following Python program to generate code:
#! /usr/bin/env python2.6
import sys;
cppcode="""
#include <iostream>
#include <cstdlib>
int main(int argc, char* argv[])
{
int %s = 0;
return 0;
}
"""
def longvarname(n):
str="x";
for i in xrange(n):
str = str+"0";
return str;
def printcpp(n):
print cppcode % longvarname(n);
if __name__=="__main__":
if len(sys.argv)==2:
printcpp(int(sys.argv[1]));
This generates C++ code using the desired length variable name. Using the following:
./gencpp.py 1048576 > main.cpp g++ main.cpp -o main
The above gives me no problems (the variable name is roughly 1MB in length). I tried for a gigabyte, but I'm not being so smart with the string construction, and so I decided to abort when gencpp.py took too long.
Anyway, I very much doubt that gcc pre-allocates 1MB for variable names. It is purely bounded by memory.
这篇关于g ++变量名有长度限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!