* useless expression in typesaft_cb_cast
@ 2018-03-11 20:05 Yubin Ruan
2018-03-13 9:49 ` Rusty Russell
0 siblings, 1 reply; 2+ messages in thread
From: Yubin Ruan @ 2018-03-11 20:05 UTC (permalink / raw)
To: ccan
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
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: useless expression in typesaft_cb_cast
2018-03-11 20:05 useless expression in typesaft_cb_cast Yubin Ruan
@ 2018-03-13 9:49 ` Rusty Russell
0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2018-03-13 9:49 UTC (permalink / raw)
To: Yubin Ruan, ccan
Yubin Ruan <ablacktshirt@gmail.com> writes:
> 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
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-13 9:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-11 20:05 useless expression in typesaft_cb_cast Yubin Ruan
2018-03-13 9:49 ` Rusty Russell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox