Maximum number of arguments in a function call

A

ashok.anbalan

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
 
I

infobahn

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?

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.
 
L

Lawrence Kirby

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.

It is 127 in C99.

Lawrence
 
S

Serve Lau

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

Generated code perhaps?
 
J

Julian V. Noble

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

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
(e-mail address removed)
^^^^^^^^^^^^^^^^^^
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)
 
A

ashok.anbalan

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
 
J

jacob navia

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
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!
 
D

DHOLLINGSWORTH2

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 :
typedef struct t {
char b[1024*1024*10]; // 10mb array.
} T;

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

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 said:
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
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top