Source-Changes-D archive

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

Re: CVS commit: src/share/misc



    Date:        Wed, 31 Mar 2021 03:03:53 -0000 (UTC)
    From:        christos%astron.com@localhost (Christos Zoulas)
    Message-ID:  <s40oqp$c71$1%ciao.gmane.io@localhost>

  | There are 3 x 'sizeof(' in the tree compared to 'sizeof ' in '*.c' and
  | I am counting 'sizeof (' as 'sizeof ':
  |
  | 191337 'sizeof('
  |  63508 'sizeof '
  |
  | I think that it is better to bless the prevailing majority as the rule,
  | but we should let others express their opinions first.

That's not a reasonable count, as it ignores (or rather, includes) the
cases where sizeof requires the '(' - all that should be being counted,
that is, if this were a reasonable way to decide anything, would be the
uses of sizeof where the parentheses are optional.

Personally, my main preference would be for fewer rules.   If there isn't
a really good reason for there to be a rule, there shouldn't be one.

Here, as I recall it, the issue only arose because of something either
lint or indent was doing, or wanted to do.   I don't recall which, but
I do not remember any earlier complaints from anyone that they couldn't
understand code because of missing () around a variable name arg to sizeof.

If the instigator was lint, then it should simply ignore this issue (and
all other issues which are simply style) - if it encounters something which
is truly potentially ambiguous, sure, issue a warning (but with some easy
method to shut it up if the warning is bogus), but otherwise, nothing.

If it was indent, then I don't much care what it does, but I'd prefer it to
leave most hand crafted code alone, unless it really has to be fixed.  I
see no compelling reason for it to ever fiddle the arg to sizeof (except
perhaps if someone inserted a line break between the two).

For the issue in question, my personal preference is for sizeof variable to
not have parentheses (including in cases like sizeof *ptr, sizeof ptr->field
and sizeof struct.field), unless they really are needed for readability, or
accuracy.   Parentheses are required for sizeof(type) of course, I don't
much care whether there's a space between 'sizeof' and '(' or not, I'd leave
that to whoever is inserting the code - the only caveat being to retain the
style of the original (if other uses have a space, use it, if they don't,
omit it).   I prefer not to do sizeof (expression) at all, but in the very
rare case it is needed, the parentheses are required (of course), and in those
unless there's a good reason not to (line length is one) I'd normally include
the space before the '('.

But those are just my preferences, and when I modify code, I follow the style
of the original (I even used Steve Bourne's algol68-like crap when doing some
minor modifications to adb long long long ago).

I see no need for a rule.   Just leave things as they were a month ago, and
we can all remain happy.

kre



Home | Main Index | Thread Index | Old Index