j0******@engineer.com (j0mbolar) writes:
given this example:
void bar(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
baz(fmt, ap);
va_end(ap);
}
void baz(const char *fmt, va_list ap)
{
char msg[MSG_SIZE];
vsnprintf(msg, sizeof msg, fmt, ap);
display(msg);
}
is this usage well defined? that is, passing a va_list
from one function and using it in another.
Yes.
also, i've been wondering about something.
where in the standard is the following explained?
void func(int foo);
...
(****func)(foo); /* where is this method of calling func explained? */
6.3.2.1#4:
| A function designator is an expression that has function type. Except
| when it is the operand of the sizeof operator or the unary & operator,
| a function designator with type "function returning type" is converted
| to an expression that has type "pointer to function returning type".
6.5.3.2#4:
| The unary * operator denotes indirection. If the operand points to a
| function, the result is a function designator; [...].
6.5.2.2#1 (Function calls, Constraints):
| The expression that denotes the called function shall have type
| pointer to function returning void or returning an object type other
| than an array type.
6.5.2.2#3 (Function calls, Semantics):
| A postfix expression followed by parentheses () containing a possibly
| empty, comma-separated list of expressions is a function call. The
| postfix expression denotes the called function. The list of
| expressions specifies the arguments to the function.
The function designator `func', which has type `function returning
void', is not the operand of a `sizeof' or unary & operator, therefore
it is converted to type `pointer to function returning void'. The
innermost * operator is then applied; the result of the expression
`*func' has type `function returning void', but it is again not the
operand of a `sizeof' or unary & operator, so it is again converted to
type `pointer to function returning void'. This happens repeatedly.
Finally, the result of `(****func)' has type `pointer to function
returning void' (after conversion according to 6.3.2.1#4), and the
function is called according to 6.5.2.2#3.
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- )
http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/