0

I want to know how the va_start(ap, parmN) macro works? I've read that parmN is number of optional arguments that is being passed, but at some places I noticed that const char *pointer is passed as parmN. I want to know how va_start() work and why it work in above both cases?

I've read this How to use va_start()? but I'm unable to understand as it has no good explanation and people are referring to same sentence quoted from the standard which say very little about va_start() working.

I'll be glad if someone explain this.

Ravi Raj
  • 151
  • 1
  • 11
  • It is architecture-dependent. If you really want to know ,you could study the macro (src) or look at the generated assembler code. – wildplasser Nov 15 '20 at 11:33
  • 1
    In general `parmN` is not the number of optional arguments. It is just the last argument before `...`. It could mean anything depending on the application. Please clarify your question. Do you want to know how to use `va_start`, or how it achieves what it needs to achieve? The latter is architecture-dependent. – n. m. could be an AI Nov 15 '20 at 11:39
  • 1
    Related: [How are variable arguments implemented in gcc?](https://stackoverflow.com/q/12371450/440558) – Some programmer dude Nov 15 '20 at 11:41
  • @n.'pronouns'm. First I'll want to know how to use `va_start()`. – Ravi Raj Nov 15 '20 at 12:04
  • There is an example for `va_start()` usage in the linux manpage. – wildplasser Nov 15 '20 at 13:01
  • 1
    You pass it two arguments, `ap` and the last named parameter of the function before `...`. That's all there is to it. There is no wiggle room at all. – n. m. could be an AI Nov 15 '20 at 14:33

0 Answers0