function参数最大数量
我没有发现C99标准中计数函数参数的任何限制,我想它只受堆栈大小的限制。
但是,我编写了一个简单的测试程序来演示具有大量参数的函数的行为。 当它大约10k时,我在gcc上遇到以下错误(gg版本4.5.3在Cygwin上):
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../libcygwin.a(libcmain.o):(.text+0xa9): undefined reference to `_WinMain@16'
我意识到这么大的参数数量不太可能,但我想知道编译器的哪个参数决定了这个限制?
编辑
用于生成C源代码的脚本
#!/bin/sh num=$1 echo "" > out.c echo "#include " >> out.c echo "int getsum( " >> out.c i=0 while [ $i -lt $num ] do ((i++)) if [ $i -eq $num ] then echo "int p$i )" >> out.c else echo -ne "int p$i," >> out.c fi done echo "{" >> out.c echo -ne " return " >> out.c i=0 while [ $i -lt $num ] do ((i++)) if [ $i -eq $num ] then echo "p$i;" >> out.c else echo -ne "p$i + " >> out.c fi done echo "}" >> out.c echo "int main(){" >> out.c echo "printf(\"Sum of %d elements is %d\", $num, getsum(" >> out.ci=0 while [ $i -lt $num ] do ((i++)) if [ $i -eq $num ] then echo "$i" >> out.c else echo -ne "$i," >> out.c fi done echo "));" >> out.c echo "return 0;}" >> out.c gcc out.c ./a.exe
标准规定了每个实施必须支持的某个最小数量,
5.2.4.1翻译限制
– 一个函数定义中的127个参数
– 一个函数调用中的127个参数