Re: [PATCH] linux/const.h: Explain how __is_constexpr() works

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jan 31, 2022 at 9:43 PM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
>
> + * - The conditional operator ("... ? ... : ...") returns the type of the
> + *   operand that isn't a null pointer constant. This behavior is the

Perhaps clarify that this happens only if it fits that case? ...

> + * - If (x) is an integer constant expression, then the "* 0l" resolves it
> + *   into a null pointer constant, which forces the conditional operator
> + *   to return the type of the last operand: "(int *)".
> + * - If (x) is not an integer constant expression, then the type of the
> + *   conditional operator is from the first operand: "(void *)".

... i.e. this one happens because it is specified as returning a
pointer to void (one could read it as returning the type of the first
operand).

What about something like:

  - The behavior (including its return type) of the conditional
operator ("... ? ... : ...") depends on the kind of expressions given
for the second and third operands. This is the central mechanism of
the macro.
  - If (x) is an integer constant expression, then the "* 0l" resolves
it into a null pointer constant. When one operand is a null pointer
constant and the other is a pointer, the conditional operator returns
the type of the pointer operand; that is, "int *".
  - If (x) is not an integer constant expression, then that operand is
a pointer to void (but not a null pointer constant). When one operand
is a pointer to void and the other a pointer to an object type, the
conditional operator returns a "void *" type.

Cheers,
Miguel



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux