Alex Rivera | Logout

In C, when is conditional "test ? : alt" form (empty true case) supported?

Asked 2012-06-08T09:24:18.853
14

In gcc, I can write foo ? : bar which is a shorthand form of foo ? foo : bar but I see that K&R doesn't mention it.

Is this something I should rely on, defined in some standard? Or just an (evil) gcc extension I should avoid?

Edit
Report

1 Answer

4

This is a GCC extension. It's not part of the C standard, but the GCC compiler lets you use it. See its documentation for details, and be mindful of its behavioural differences to the "equivalent" ternary expression.

answered 2012-06-08T09:27:58.330

Your Answer