Re: conditional operator ?: usage (Linux kernel)

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

 



On Wed, Oct 02, 2019 at 10:19:42AM -0700, Linus Torvalds wrote:
> 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?

Yes, it shouldn't be a problem, certainly the 'one side is void and
the result is void'. It makes sense. But I prefer to avoid something
with 'unless the result isn't used', hehe.

-- Luc



[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