Skip to main content
Edited in reponse to a comment.
Source Link
Sergey Kalinichenko
  • 729.1k
  • 85
  • 1.2k
  • 1.6k

The lastfirst two calls that you show are undefined behavior according to the C standardstandard; only the call that passes the last named parameter is correct. However, you get good behavior on gcc, because gcc compilers ignore the second parameter of va_start, using a different technique to find the end of the argument list:

The traditional implementation takes just one argument, which is the variable in which to store the argument pointer. The ISO implementation of va_start takes an additional second argument. The user is supposed to write the last named argument of the function here. However, va_start should not use this argument. The way to find the end of the named arguments is with the built-in functions described below {link}.

The last two calls that you show are undefined behavior according to the C standard. However, you get good behavior on gcc, because gcc compilers ignore the second parameter of va_start, using a different technique to find the end of the argument list:

The traditional implementation takes just one argument, which is the variable in which to store the argument pointer. The ISO implementation of va_start takes an additional second argument. The user is supposed to write the last named argument of the function here. However, va_start should not use this argument. The way to find the end of the named arguments is with the built-in functions described below {link}.

The first two calls that you show are undefined behavior according to the C standard; only the call that passes the last named parameter is correct. However, you get good behavior on gcc, because gcc compilers ignore the second parameter of va_start, using a different technique to find the end of the argument list:

The traditional implementation takes just one argument, which is the variable in which to store the argument pointer. The ISO implementation of va_start takes an additional second argument. The user is supposed to write the last named argument of the function here. However, va_start should not use this argument. The way to find the end of the named arguments is with the built-in functions described below {link}.

Source Link
Sergey Kalinichenko
  • 729.1k
  • 85
  • 1.2k
  • 1.6k

The last two calls that you show are undefined behavior according to the C standard. However, you get good behavior on gcc, because gcc compilers ignore the second parameter of va_start, using a different technique to find the end of the argument list:

The traditional implementation takes just one argument, which is the variable in which to store the argument pointer. The ISO implementation of va_start takes an additional second argument. The user is supposed to write the last named argument of the function here. However, va_start should not use this argument. The way to find the end of the named arguments is with the built-in functions described below {link}.