【发布时间】:2012-02-20 12:43:42
【问题描述】:
我没有发现 C99 标准中对 count 函数参数有任何限制,我猜它只受堆栈大小的限制。
但是,我编写了一个简单的测试程序来演示具有大量参数的函数的行为。当它大约 10k 时,我在 gcc 上收到以下错误(Cygwin 上的 gcc 版本 4.5.3):
/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 <stdio.h>" >> 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.c
i=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
【问题讨论】:
-
愿意分享导致此问题的代码吗?
-
@Martinsh Shaiters 我写了一些 sh 脚本来生成源代码。查看更新
标签: c parameter-passing stack-overflow