kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Solomon Tan <wjsota@gmail.com>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: Coding style operator precedence
Date: Fri, 22 Apr 2022 16:59:38 +0200	[thread overview]
Message-ID: <YmLC2sW7A7gAllhw@kroah.com> (raw)
In-Reply-To: <YmK29mxOdFv0HzwB@ArchDesktop>

On Fri, Apr 22, 2022 at 10:08:54PM +0800, Solomon Tan wrote:
> Hey all,
> 
> Could someone share what the coding style preference is where operator
> precedence is concerned?
> 
> I notice in the staging drivers that there are many instances where
> there are parenthesis in statements where operator precedence should be
> (in my opinion) obvious. Yet, there doesn't seem to be a patch to amend
> it. For example:
> 
> In vc04_services/interface/vchiq_arm/vchiq_core.c, line 2136, there is
> ```
> slot_zero->master.slot_last = first_data_slot + (num_slots / 2) - 1;
> ```
> It could just have been
> ```
> slot_zero->master.slot_last = first_data_slot + num_slots / 2 - 1;
> ```
> yet I do not see anyone patching it. Nothing is mentioned in the kernel
> docs about operator precedence. Checkpatch.pl doesn't highlight it
> as a coding style either. 

Because as-is, it is fine.

> What is the concensus regarding operator precedence in kernel coding
> style? The most relevant email thread I found suggests some feel the
> parenthesis shouldnt be there, while others would leave it there for
> readability.
> https://lore.kernel.org/linux-staging/YRypyev4Ku3eI9w8@kroah.com/ 

Make it obvious when people read the code as we do not always remember
the precedence order.  We write code for people first, compilers second.

thanks,

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply	other threads:[~2022-04-22 15:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22 14:08 Coding style operator precedence Solomon Tan
2022-04-22 14:59 ` Greg KH [this message]
2022-04-22 15:44   ` Solomon Tan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YmLC2sW7A7gAllhw@kroah.com \
    --to=greg@kroah.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=wjsota@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).