lkml.org 
[lkml]   [2011]   [Apr]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH 01/11] ftrace/trivial: Clean up recordmcount.c to use Linux style comparisons
On 04/20/2011 07:28 PM, Steven Rostedt wrote:
> From: Steven Rostedt <srostedt@redhat.com>
>
> The Linux style for comparing is:
>
> var == 1
> var > 0
>
> and not:
>
> 1 == var
> 0 < var
>
> It is considered that Linux developers are smart enough not to do the
>
> if (var = 1)
>
> mistake.

It's not just a matter of 'smart', it's a matter of safety.
For me it still catches a bug (typo, copy+paste, fumble in editor script, ...)
every year or two. Compilers haven't always warned, or the option to warn
might be turned off.

> - return 0 == strcmp(".text", txtname) ||
> + return strcmp(".text", txtname) == 0 ||

I consider "0==strcmp(" to be an idiom. Too often "strcmp(...) == 0"
overflows my mental stack because of the typographic width of the operands
in the source code. If you still object in this case then please consider
using something like:
#define strequ(a,b) (strcmp((a), (b)) == 0)
or
static int strequ(char const *a, char const *b)
{
return strcmp(a, b) == 0;
}
which names the idiom.

--
John Reiser


\
 
 \ /
  Last update: 2011-04-22 17:21    [W:0.297 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site