Re: conditional operator ?: usage (Linux kernel)

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

 



On Tue, Oct 1, 2019 at 11:16 PM Randy Dunlap <rdunlap@xxxxxxxxxxxxx> wrote:
>
> I don't mind the use of ?: for choosing values, but it seems odd to me
> to use it for calling functions, as in:  [from drivers/clocksource/timer-of.c),
> line 28 in Linux 5.4-rc1):
>
>         of_irq->percpu ? free_percpu_irq(of_irq->irq, clkevt) :
>                 free_irq(of_irq->irq, clkevt);

Ugh. It looks like a gcc extension for when the result of a
conditional expression isn't used.

The result of the conditional expression _should_ be the type of
either side (usual type conversions). And it's fine if *both* sides
are of type 'void', then the result should be of that type too.

But it looks like gcc (and clang) allow one side to be void, and the
result is void.

Hmm.

> gcc doesn't complain about the ?: usage.  Is sparse correct here or is it being
> too strict?

Sparse is correct, but maybe sparse should accept the gcc extension
except when in some strict mode?

We have a (somewhat similar) issue with Wreturn_void - we accept the
syntax "return voidexpr;" in a function returning void, even if the
standard explicitly says that a void function shall have no
expression.

          Linus



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux