Maximum length of argument list

This is a discussion on Maximum length of argument list within the C Programming forums, part of the General Programming Boards category; Hi everyone, does anyone know if there is a maximum number of arguments that can be passed to a function?...

  1. #1
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426

    Maximum length of argument list

    Hi everyone,
    does anyone know if there is a maximum number of arguments that can be passed to a function?

  2. #2
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    987
    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:
    Quote Originally Posted by C99
    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 arguments in one function call
    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.

  3. #3
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    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.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Quote Originally Posted by TheBigH View Post
    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.
    I've never seen a well-written function take 25 arguments. Maybe it's time to look at some kind of encapsulation. A struct perhaps?
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    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.

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Quote Originally Posted by TheBigH View Post
    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.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by TheBigH View Post
    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.
    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.

  8. #8
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Okay, you guys have convinced me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  2. Pointer to List Iterator As Function Argument
    By bengreenwood in forum C++ Programming
    Replies: 8
    Last Post: 06-17-2009, 05:30 AM
  3. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 03:09 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21