In GCC you'll get a warning if you write:

if (x = 6) ...

and, at least in the case of ODP, where we compile with warnings treated as
errors, the code will fail compilation.  To intentionally do an assignment
within an if you need an extra set of parentheses:

if ((x = 6) == somevar) ...

which confirms that you intended = vs. ==.

Currently, checkpatch flags as an error single statements that have braces:

if (x) {
      ....single statement
}

and insists on :

if (x)
   ...single statement

Personally I see nothing wrong with either convention. The former has the
advantage that if you want to add another line to the test at some point in
the future you don't have to also add the braces.

On Thu, Nov 20, 2014 at 4:21 AM, Taras Kondratiuk <
[email protected]> wrote:

> On 11/20/2014 10:15 AM, Maxim Uvarov wrote:
> > On 11/20/2014 01:49 AM, Anders Roxell wrote:
> >> On 2014-11-19 16:23, Mike Holmes wrote:
> >>> On 19 November 2014 16:13, Maxim Uvarov <[email protected]>
> wrote:
> >>>
> >>>> On 11/19/2014 11:21 PM, Mike Holmes wrote:
> >>>>
> >>>>>
> >>>>> On 19 November 2014 10:36, Yan Songming <[email protected]
> >>>>> <mailto:
> >>>>> [email protected]>> wrote:
> >>>>>
> >>>>>      New API implementing odp_shm_free to match the odp_shm_reserve.
> >>>>>
> >> [...]
> >>
> >>>>>      +       uint64_t alloc_size;
> >>>>>      +
> >>>>>      +       i = from_handle(shm);
> >>>>>      +       if (odp_shm_tbl->block[i].addr == NULL) {
> >>>>>
> >>>>>
> >>>>> Would it be better to follow the slightly better habit of reversing
> >>>>> the
> >>>>> constant with the variable
> >>>>>
> >>>>> NULL == odp_shm_tbl->block[i].addr
> >>>>>
> >>>> why is that better? I always write tested variable first.
> >>>>
> >>> http://www.drpaulcarter.com/cs/common-c-errors.php#2.2
> >>>
> >>> Basically the reverse habit if applied uniformly removes the chance
> >>> of the
> >>> linked silly mistake, if we adopt that for ODP we will make it harder
> to
> >>> suffer from the issue. But we would have to do it uniformly for best
> >>> effect
> >>> so that during a review it catches your eye.
> >> +1 for Mike's suggestion.
> >
> > Thanks, that is reasonable. Sometime I really did = instead of == in the
> > past.
>
> That's a matter of taste. Modern compiler will give you a warning if in
> the code above = is used instead of ==.
> Personally I prefer a direct form, because it is logical and easier to
> read.
>
> _______________________________________________
> lng-odp mailing list
> [email protected]
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to