功能参数最大数 [英] Function parameters max number

查看:167
本文介绍了功能参数最大数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有找到在C99标准计数功能参数的任何限制,我想这只能通过堆栈大小的限制。

不过,我已经写了一个简单的测试程序来演示用的参数大计数功能的行为。当其10K左右,我得到(在Cygwin的gcc版本4.5.3)上GCC以下错误:

  /usr/lib/gcc/i686-pc-cygwin/4.5.3 /../../../ libcygwin.a(libcmain.o):(。文本+ 0xa9):未定义的引用`_WinMain @ 16

我认识到的参数,大计数是不可能的,但我不知道什么参数的编译器来确定这个限制?

修改

脚本生成C代码

 #!/ bin / sh的NUM = $ 1回声> out.c
回声的#include<&stdio.h中GT; >> out.c回声INT getsum(>> out.cI = 0
而[$ I $ -lt NUM]

    ((我+ +))
    如果[$ I $ -eq NUM]
    然后
        回声INT p $ I)>> out.c
    其他
        回声-neINT p $ I,>> out.c
    科幻
DONE回声{>> out.c回声-ne回归>> out.cI = 0
而[$ I $ -lt NUM]

    ((我+ +))
        如果[$ I $ -eq NUM]
        然后
                回声P $ I; >> out.c
        其他
                回声-neP $ I +>> out.c
        科幻
DONE回声}>> out.c回声INT的main(){>> out.c
回声%d个元素的printf(\\总和为%d \\,$ num个,getsum(>> out.cI = 0
而[$ I $ -lt NUM]

        ((我+ +))
        如果[$ I $ -eq NUM]
        然后
                回声$ I>> out.c
        其他
                回声-ne$ I>> out.c
        科幻
DONE回声)); >> out.c回声返回0;}>> out.c
GCC out.c
./a.exe


解决方案

本标准规定一定的最低数量每它实现必须支持,

5.2.4.1翻译限制


  

- 127参数函数定义结果
   - 127论点一个函数调用


I did not find any limitation of count function parameters in the C99 standard and I guess it is only limited by stack size.

However I've written a simple test program to demonstrate the behavior of a function with a large count of parameters. When its about 10k, I get the following error on gcc (gcc version 4.5.3 on Cygwin):

/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../libcygwin.a(libcmain.o):(.text+0xa9): undefined reference to `_WinMain@16'

I realize that such large count of parameters is unlikely but I wonder what parameter of the compiler determines this limit?

EDIT

script to generate C-source

#!/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

解决方案

The Standard specifies a certain minimum number which every implementation must support,

5.2.4.1 Translation Limits

— 127 parameters in one function definition
— 127 arguments in one function call

这篇关于功能参数最大数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆