D
Dan Henry
I have run across functions in the Linux kernel's MTD driver that have
me scratching my head a bit. The functions have the general form:
extern int bar(size_t len, size_t *retlen, unsigned char *buf);
int foo(size_t len, unsigned char *buf) {
size_t retlen;
int ret;
ret = bar(len, &retlen, buf);
return ret ? : retlen; /* <-- void expression and UB? */
}
It is foo()'s return statement that I am soliciting comments about. Am
I correct that the conditional operator's second operand is a void
expression and if so, doesn't that invoke undefined behavior by
attempting to use the value of a void expression? I sometimes
struggle interpreting the standard and hope I haven't overlooked
something, but I can't find the verse that might bless the statement.
If it is allowed, what value would foo() return for nonzero ret --
zero?
Thanks,
me scratching my head a bit. The functions have the general form:
extern int bar(size_t len, size_t *retlen, unsigned char *buf);
int foo(size_t len, unsigned char *buf) {
size_t retlen;
int ret;
ret = bar(len, &retlen, buf);
return ret ? : retlen; /* <-- void expression and UB? */
}
It is foo()'s return statement that I am soliciting comments about. Am
I correct that the conditional operator's second operand is a void
expression and if so, doesn't that invoke undefined behavior by
attempting to use the value of a void expression? I sometimes
struggle interpreting the standard and hope I haven't overlooked
something, but I can't find the verse that might bless the statement.
If it is allowed, what value would foo() return for nonzero ret --
zero?
Thanks,