mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "John Kacur" <jkacur@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Subject: drop overzealous ERROR: do not initialise statics to 0 or NULL from checkpatch.pl
Date: Wed, 13 Aug 2008 12:39:45 +0200	[thread overview]
Message-ID: <520f0cf10808130339r5dd22e12w3477d6bddd545db1@mail.gmail.com> (raw)

Could we drop this somewhat overzealous "ERROR: do not initialise
statics to 0 or NULL" from checkpatch.pl?

Reasoning:
1. This is not part of Documentation/CodingStyle
2. K&R 2nd.ed do it (pg 83, static int bufp = 0;) The purpose is to
remove access to the bufp from external routines, and to avoid name
conflict)
3. It can be a good form of documentation.
4. It creates a lot of needless code churn to change this kind of
thing for no good reason.
5. It doesn't even change the object size (thus kernel size) to do so.
Demo with user space code.

jkacur@linux-ipxk:~/try> cat foo.c
#include <stdio.h>
#include <stdlib.h>

static int a[1000];

/* Function Prototype */
void foo(void);
int main(void)
{
        exit(0);
}

void foo(void)
{
        static int b[1000];
        static int c;
}
jkacur@linux-ipxk:~/try> gcc foo.c
jkacur@linux-ipxk:~/try> size a.out
   text    data     bss     dec     hex filename
   1203     520    8064    9787    263b a.out
jkacur@linux-ipxk:~/try> ls -l a.out
-rwxr-xr-x 1 jkacur users 11237 2008-08-13 12:26 a.out

Now initialize all the statics to 0 and there will be no difference in
the object size
jkacur@linux-ipxk:~/try> cat foo.c
#include <stdio.h>
#include <stdlib.h>

static int a[1000] = {0};

/* Function Prototype */
void foo(void);
int main(void)
{
        exit(0);
}

void foo(void)
{
        static int b[1000] = {0};
        static int c = 0;
}
jkacur@linux-ipxk:~/try> gcc foo.c
jkacur@linux-ipxk:~/try> size a.out
   text    data     bss     dec     hex filename
   1203     520    8064    9787    263b a.out
<----------------------- No difference with the initialization to 0!!!
jkacur@linux-ipxk:~/try> ls -l a.out
-rwxr-xr-x 1 jkacur users 11237 2008-08-13 12:26 a.out
<----------------------- No difference with the initialization to 0!!!


Now if we initialize it to a value other than 0 or NULL, then the bss
is decreased at the expense of the data section, which does indeed
increase the object size, however checkpatch.pl doesn't complain about
this. (it is valid to do this)
jkacur@linux-ipxk:~/try> cat foo.c
#include <stdio.h>
#include <stdlib.h>

static int a[1000] = {1};

/* Function Prototype */
void foo(void);
int main(void)
{
        exit(0);
}

void foo(void)
{
        static int b[1000] = {1};
        static int c = 1;
}
jkacur@linux-ipxk:~/try> gcc foo.c
jkacur@linux-ipxk:~/try> size a.out
   text    data     bss     dec     hex filename
   1203    8568      16    9787    263b a.out
jkacur@linux-ipxk:~/try> ls -l a.out
-rwxr-xr-x 1 jkacur users 19301 2008-08-13 12:27 a.out

             reply	other threads:[~2008-08-13 10:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-13 10:39 John Kacur [this message]
2008-08-13 11:50 ` John Kacur
2008-08-13 12:15 ` Arnd Bergmann
2008-08-13 20:19   ` Guennadi Liakhovetski
2008-08-14  8:42     ` John Kacur

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=520f0cf10808130339r5dd22e12w3477d6bddd545db1@mail.gmail.com \
    --to=jkacur@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®