+ 12

How many parameters can pass in a function?

29th Jun 2019, 1:13 PM
Bhargava Ram
Bhargava Ram - avatar
16 Réponses
+ 28
This limit is determined by stacked frame size, which is set by OS. Theoretically you can set these max stack size to 8192 bits. Each variable takes up 32 bits then you could pass 256 parameters. 8192/32 = 256.
1st Jul 2019, 12:17 PM
A J I L
A J I L - avatar
+ 12
There is no maximum limit to pass parameters or arguments to a user defined function. But for a pre-defined function it depends.
30th Jun 2019, 5:10 PM
Manoj
Manoj - avatar
+ 9
In the case of ordinary functions, as per §5.2.4.1 " The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits*: [...] — 127 parameters in one function definition — 127 arguments in one function call [...] * Implementations should avoid imposing fixed translation limits whenever possible. " For variadic functions (like `printf()`), the above limitations wouldn't be the case. https://port70.net/~nsz/c/c11/n1570.html#5.2.4.1
29th Jun 2019, 1:46 PM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
+ 9
I thought it was only limited by the stack. I had no idea there was a limit of 127.
29th Jun 2019, 2:05 PM
Sonic
Sonic - avatar
+ 5
Not sure, however some sources say that C functions accept at least 127 parameters. But realistically you probably will never pass that many parameters ;)
29th Jun 2019, 1:16 PM
Luk
Luk - avatar
+ 5
you can pass as many as you want..... but according to standard of Compiler you're using C has a limit of 127.....
1st Jul 2019, 2:03 AM
Aditya
Aditya - avatar
+ 4
Using arrays you can pass as many as you want.
29th Jun 2019, 2:55 PM
Seb TheS
Seb TheS - avatar
+ 4
"I thought it was only limited by the stack" Actually, that limitation mirrors the underlying stack frame[1] size imposed by the architecture and implementation. [1] Each frame comprises: 1) the return address of the function 2) passed arguments 3) variables of the local scope of the function.
29th Jun 2019, 3:40 PM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
+ 4
You can pass as much as you want, but I don't think that you will ever have a function that has more than 5-10 parameters, in that case define another function 👌😘
29th Jun 2019, 3:50 PM
Dejan Francuz🥇
Dejan Francuz🥇 - avatar
+ 4
There isn't a limit
30th Jun 2019, 10:46 PM
Candice Dick
Candice Dick - avatar
+ 4
There IS a limit imposed by the "default" size of the stack frame (~8MB on Linux, and ~1MB on Windows). If you define a huge data structure like typedef struct { char *c, *cc, *ccc; int *m, *n; double x[1000]; double y[1000]; double z[1000]; }d_t; with the size of ~24KB without increasing the stack size you'll end up with stack overflow if you pass only 86 arguments of type `d_t` to function `f` instead of 85 or fewer. So somebody may say passing 1 million arguments is possible but without saying of "what type" then chances are s/he ends up with catastrophic consequences. The following code is a testament to this fact. https://code.sololearn.com/cFrv310ct2XH It worth mentioning that the available stack space in this particular implementation has been increased to +2MB and there's a fat chance that executing the above sample causes stack overflow on a different implementation.
1st Jul 2019, 6:49 AM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
+ 4
The limit is based on stack frame size , we can set these max stack size to 8192 bits. Each variable takes up to 32 bits . Means we can pass 256 parameters
7th Jul 2020, 8:46 AM
Bhargava Ram
Bhargava Ram - avatar
+ 3
Its has no limit
7th Jul 2020, 7:14 AM
Harishma
Harishma - avatar
+ 2
As many as you want to perform the task... or use variable length argument..
4th Jul 2019, 8:38 AM
Mohit Chauhan
+ 2
Not limited
9th Jul 2019, 5:17 AM
yasmeenalhajjaj
yasmeenalhajjaj - avatar
+ 1
As many as you want
30th Jun 2019, 9:19 PM
Durjan Sodha
Durjan Sodha - avatar