Hi everyone,
does anyone know if there is a maximum number of arguments that can be passed to a function?
Hi everyone,
does anyone know if there is a maximum number of arguments that can be passed to a function?
In C89, compilers must support at least 31 arguments. In C99, that's been increased to 127.
Technically a compiler need only be able to handle one such call per program:
You can probably pretty safely assume that multiple such calls will work. I would consider a compiler that couldn't do that to be effectively broken, even if it is not actually violating the standard.Originally Posted by C99
Cool. I will only have one such function in my program, and I doubt if I'll get to more than about 25 arguments. Thanks for your help.
In this case, I am reading a bunch of different and unrelated parameters from a file. Rather than treat all the parameters as elements of a struct, I prefer to pass the addresses of each parameter to the long-argument-list function. This is because I will have other functions that will use some of the parameters, but not all of them, and I'd rather just pass them the ones they need.
Maybe it makes sense in your case. I don't have all the details so I can't really judge. But if it's an efficiency thing you're trying to gain then it would be much faster to just pass a single pointer to the struct to your functions instead of up to 25 different arguments.
If you understand what you're doing, you're not learning anything.
It would be simpler and far more reliable to pass in the struct and only use what you need inside the function...
If the function has to change values in the struct that reflect outside the function, pass in the address of the struct and work on it from inside the function.
You'll find a far lower risk of coding errors and no real downside.
Okay, you guys have convinced me.