Function parameters max number

2019-01-12 03:28发布

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

1条回答
仙女界的扛把子
2楼-- · 2019-01-12 04:09

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

查看更多
登录 后发表回答