Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function definition with an ellipsis

I have misunderstanding about the semantic of functions with variable number of arguments. 6.5.2.2(p6):

If the function is defined with a type that includes a prototype, and either the prototype ends with an ellipsis (, ...) or the types of the arguments after promotion are not compatible with the types of the parameters, the behavior is undefined.

This is not really clear. Does in the function definition below the prototype end with an ellipsis?

void foo(int i, ...){
    //...
}

At first I thought that it was about the function the parameter list contains the ellipsis only, like

void foo(...){
    //...
}

but this case is described by 6.9.1(p8):

If a function that accepts a variable number of arguments is defined without a parameter type list that ends with the ellipsis notation, the behavior is undefined

So I don't really understand what did they mean by

either the prototype ends with an ellipsis (, ...)

at 6.5.2.2(p6)

like image 884
Some Name Avatar asked Jun 25 '26 03:06

Some Name


1 Answers

This paragraph discusses the case where a function call expression mentions a function for which no prototype has been seen. In this case, the compiler has to guess at the types of its parameters, based on types of arguments of the call.

If that function is defined (possibly in a different translation unit) as variadic, or with parameter types that don't match the compiler's guess, the behavior is undefined.

like image 81
Igor Tandetnik Avatar answered Jun 26 '26 20:06

Igor Tandetnik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!