Connecting Tech Pros Worldwide Forums | Help | Site Map

Maximum number of arguments in a function call

ashok.anbalan@gmail.com
Guest
 
Posts: n/a
#1: Nov 14 '05
Hi,

Can someone tell me if the language imposes any restrictions on the
maximum number of arguments that can be passed via a function call?

Thanks,
Ashok


infobahn
Guest
 
Posts: n/a
#2: Nov 14 '05

re: Maximum number of arguments in a function call


ashok.anbalan@gmail.com wrote:[color=blue]
>
> Hi,
>
> Can someone tell me if the language imposes any restrictions on the
> maximum number of arguments that can be passed via a function call?[/color]

C90 requires implementations to support at least 31 function parameters.
Therefore, portable code should not use more than that number. It is
possible that C99 is more generous to programmers, but I have not
checked this.
Lawrence Kirby
Guest
 
Posts: n/a
#3: Nov 14 '05

re: Maximum number of arguments in a function call


On Tue, 01 Mar 2005 10:47:08 +0000, infobahn wrote:
[color=blue]
> ashok.anbalan@gmail.com wrote:[color=green]
>>
>> Hi,
>>
>> Can someone tell me if the language imposes any restrictions on the
>> maximum number of arguments that can be passed via a function call?[/color]
>
> C90 requires implementations to support at least 31 function parameters.
> Therefore, portable code should not use more than that number. It is
> possible that C99 is more generous to programmers, but I have not
> checked this.[/color]

It is 127 in C99.

Lawrence

Randy Howard
Guest
 
Posts: n/a
#4: Nov 14 '05

re: Maximum number of arguments in a function call


In article <pan.2005.03.01.11.39.54.453000@netactive.co.uk> ,
lknews@netactive.co.uk says...[color=blue]
> On Tue, 01 Mar 2005 10:47:08 +0000, infobahn wrote:
>[color=green]
> > ashok.anbalan@gmail.com wrote:[color=darkred]
> >>
> >> Hi,
> >>
> >> Can someone tell me if the language imposes any restrictions on the
> >> maximum number of arguments that can be passed via a function call?[/color]
> >
> > C90 requires implementations to support at least 31 function parameters.
> > Therefore, portable code should not use more than that number. It is
> > possible that C99 is more generous to programmers, but I have not
> > checked this.[/color]
>
> It is 127 in C99.[/color]

IOW they are LESS generous to programmers. Who wants to work on a
function call with even 31 parameters, much less 127?

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Serve Lau
Guest
 
Posts: n/a
#5: Nov 14 '05

re: Maximum number of arguments in a function call



"Randy Howard" <randyhoward@FOOverizonBAR.net> wrote in message
news:MPG.1c8e457b48235d4798a112@news.verizon.net.. .[color=blue][color=green]
>> It is 127 in C99.[/color]
>
> IOW they are LESS generous to programmers. Who wants to work on a
> function call with even 31 parameters, much less 127?[/color]

Generated code perhaps?


Julian V. Noble
Guest
 
Posts: n/a
#6: Nov 14 '05

re: Maximum number of arguments in a function call


ashok.anbalan@gmail.com wrote:[color=blue]
>
> Hi,
>
> Can someone tell me if the language imposes any restrictions on the
> maximum number of arguments that can be passed via a function call?
>
> Thanks,
> Ashok[/color]

IMHO passing that many arguments to a function is an invitation to disaster.
My most serious and hard-to-locate bugs, in programs I wrote in the 1960's-80's
(until I learned not to) came from getting arguments out of order, etc.

Admittedly, with stronger type checking it is less likely to go un-noticed,
but one can still have out of order args of the same type without triggering
any warnings. Better to use arrays, structs, or similar abstractions when
a function needs lots of inputs.


--
Julian V. Noble
Professor Emeritus of Physics
jvn@lessspamformother.virginia.edu
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/

"As democracy is perfected, the office of president represents, more and
more closely, the inner soul of the people. On some great and glorious
day the plain folks of the land will reach their heart's desire at last
and the White House will be adorned by a downright moron."

--- H. L. Mencken (1880 - 1956)
Flash Gordon
Guest
 
Posts: n/a
#7: Nov 14 '05

re: Maximum number of arguments in a function call


Serve Lau wrote:[color=blue]
> "Randy Howard" <randyhoward@FOOverizonBAR.net> wrote in message
> news:MPG.1c8e457b48235d4798a112@news.verizon.net.. .
>[color=green][color=darkred]
>>>It is 127 in C99.[/color]
>>
>>IOW they are LESS generous to programmers. Who wants to work on a
>>function call with even 31 parameters, much less 127?[/color]
>
> Generated code perhaps?[/color]

You sometimes need to run through generated code with a debugger, so I
would hope not.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
ashok.anbalan@gmail.com
Guest
 
Posts: n/a
#8: Nov 14 '05

re: Maximum number of arguments in a function call


Actually, this question occured to me when I trying to find if there
could be a potential stack overflow kind of situation even if there is
no recursion in play (with no terminating condition of course).

Thanks,
Ashok

jacob navia
Guest
 
Posts: n/a
#9: Nov 14 '05

re: Maximum number of arguments in a function call


ashok.anbalan@gmail.com wrote:[color=blue]
> Actually, this question occured to me when I trying to find if there
> could be a potential stack overflow kind of situation even if there is
> no recursion in play (with no terminating condition of course).
>
> Thanks,
> Ashok
>[/color]
The standard defines that at least 127 argumnts must be supported in a
function call, at translation time.

This doesn't imply that 127 arguments should be supported at run-time
but it could give a guideline.

Of course if you have:

typedef struct t {
char b[1024*1024*10]; // 10mb array.
} T;

T t1 , t2;
....
myfunction(t1,t2);
....

many systems will crash, even if you have passed only 2 arguments!

DHOLLINGSWORTH2
Guest
 
Posts: n/a
#10: Nov 14 '05

re: Maximum number of arguments in a function call


You can have a stack overflow with no arguments in the function call. Due
to the amount of previously stacked information before the call.

You'll want to limit the # of items you pass, for speed and efficiency.

for example instead of :
[color=blue]
> typedef struct t {
> char b[1024*1024*10]; // 10mb array.
> } T;
>
> T t1 , t2;
> ...
> myfunction(t1,t2);
> ...[/color]

try
myfunction ( &t1, &t2 );

as long as you tell myfunction that t1 is a pointer to that type of struct,
then the compiler works out the proper offsets for each member. You will,
however, need to access the members using "->" instead of ".".

t1->b


"jacob navia" <jacob@jacob.remcomp.fr> wrote in message
news:422d812f$0$1218$8fcfb975@news.wanadoo.fr...[color=blue]
> ashok.anbalan@gmail.com wrote:[color=green]
>> Actually, this question occured to me when I trying to find if there
>> could be a potential stack overflow kind of situation even if there is
>> no recursion in play (with no terminating condition of course).
>>
>> Thanks,
>> Ashok
>>[/color]
> The standard defines that at least 127 argumnts must be supported in a
> function call, at translation time.
>
> This doesn't imply that 127 arguments should be supported at run-time but
> it could give a guideline.
>
> Of course if you have:
>
> typedef struct t {
> char b[1024*1024*10]; // 10mb array.
> } T;
>
> T t1 , t2;
> ...
> myfunction(t1,t2);
> ...
>
> many systems will crash, even if you have passed only 2 arguments!
>[/color]


Closed Thread