Skip to contentSkip to conversation

useless expression in typesaft_cb_cast

DISCUSSION Yubin Ruan 2 participants 2 messages Mar 11, 2018 – Mar 13, 2018

lore
Share & tools
lore

Yubin Ruan

author
#0 lore raw

Hi,

typesaft_cb_cast() is defined in typesaft_cb.h as:

    #define typesafe_cb_cast(desttype, oktype, expr)                  \
    	__builtin_choose_expr(                                        \
    		__builtin_types_compatible_p(__typeof__(0?(expr):(expr)), \
    					     oktype),                                 \
    		(desttype)(expr), (expr))

what is the point of that "0?(expr):(expr)" ?

Yubin
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#1 lore raw
Quoted 11 lines · Yubin Ruan

Hi,

typesaft_cb_cast() is defined in typesaft_cb.h as:

    #define typesafe_cb_cast(desttype, oktype, expr)                  \
    	__builtin_choose_expr(                                        \
    		__builtin_types_compatible_p(__typeof__(0?(expr):(expr)), \
    					     oktype),                                 \
    		(desttype)(expr), (expr))

what is the point of that "0?(expr):(expr)" ?

Hi Yubin!

I had to search through git history to find it! It serves to
decay a function type to a function pointer, otherwise __builtin_types_compatible_p(func, functype) returns false because func isn't a pointer to a function, it's a function.

Cheers,
Rusty.
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan