What are the arguments for and against Vaccinations?

What is the limitation of number of arguments in printf and how does variable arguments work?

  • printf takes variable number of arguments and is basically of the form  int printf(char *, ... ); But is there limitation in the number of arguments we can pass and how does this variable arguments get resolved. I mean how does our program know how many arguments to expect from where to excess it.

  • Answer:

    There is no fixed limit on the number of arguments that can be passed, tho a specific compiler may of course implement some restrictions.  Variable arguments work by simply pushing more and more variables onto the stack.  The called function is responsible for figuring out how many arguments have been passed.  In the case of printf and friends, this can be computed by looking at the number of substitutions in the format string.  Modern compilers will check that for you.  Debugging mismatches on old compilers was No Fun At All.

Tony Li at Quora Visit the source

Was this solution helpful to you?

Other answers

Determining the number of arguments comes from the OS culture. Mainframes marked the last one by setting its high bit on, all the others were off. MS-DOS passed the number of arguments in the cx register. In the Unix culture, there is no convention for passing the number of arguments. It is a deficiency, oversight, weakness. You can pass the number of arguments explicitly as the last argument i.e. first on the stack, but that's not a commonly used convention. Printf() does it by counting the number of tokens in the format string and hoping the programmer passed the same number of arguments. When counts don't match, you have a bug and a corrupted stack. Even when they do, there's no way to make them typesafe. In C++, the logical solution would be passing the argument list as a collection. That's not done because it would be too slow and would create a chicken-and-egg problem for collection methods. The solution is depending on the compiler to be smart enough to count tokens in the printf() format string. That's fine for printf, but does nothing for user functions with variable arguments. Chalk it up to a Unix cultural deficiency with no solution.

Robert Wagner

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.