+ 12
How many parameters can pass in a function?
18 ответов
+ 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.
+ 12
There is no maximum limit to pass parameters or arguments to a user defined function. But for a pre-defined function it depends.
+ 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
+ 9
I thought it was only limited by the stack. I had no idea there was a limit of 127.
+ 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 ;)
+ 5
you can pass as many as you want..... but according to standard of Compiler you're using C has a limit of 127.....
+ 4
Using arrays you can pass as many as you want.
+ 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.
+ 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 👌😘
+ 4
There isn't a limit
+ 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.
+ 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
+ 3
Its has no limit
+ 2
As many as you want to perform the task...
or use variable length argument..
+ 2
Not limited
+ 1
As many as you want