Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function parameters max number

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
like image 540
triclosan Avatar asked Jan 27 '12 14:01

triclosan


1 Answers

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

like image 66
Alok Save Avatar answered Oct 17 '22 20:10

Alok Save