I was looking at some preprocessor macros used in OpenSSL, and I came across the following from crypto/stack/safestack.h
:
#define CHECKED_STACK_OF(type, p) \
((_STACK*) (1 ? p : (STACK_OF(type)*)0))
#define CHECKED_SK_FREE_FUNC(type, p) \
((void (*)(void *)) ((1 ? p : (void (*)(type *))0)))
#define CHECKED_SK_FREE_FUNC2(type, p) \
((void (*)(void *)) ((1 ? p : (void (*)(type))0)))
I'm guessing its written that way to work around a compiler bug (probably something ancient that hasn't been supported in over a decade by the vendor).
What is the purpose of using the 1
above since its always true?
p
, probably - the second and third operands of the conditional operator must be convertible to the same type. – T.C. Dec 21 '14 at 2:59