public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* checkpatch.pl and statics
@ 2008-03-13 15:09 Andreas Westin XX
  2008-03-13 15:43 ` Bernd Petrovitsch
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Westin XX @ 2008-03-13 15:09 UTC (permalink / raw)
  To: linux-kernel


Hello,

I ran checkpatch.pl on a piece of code I wrote and besides all the other
warnings/errors it complained about a static pointer being initialised
to NULL/0. I fixed it but I'm curious as to why this is not permitted ?

Please cc me as I'm not on the list.

/Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: checkpatch.pl and statics
  2008-03-13 15:09 checkpatch.pl and statics Andreas Westin XX
@ 2008-03-13 15:43 ` Bernd Petrovitsch
  2008-03-16 13:34   ` Benny Halevy
  0 siblings, 1 reply; 5+ messages in thread
From: Bernd Petrovitsch @ 2008-03-13 15:43 UTC (permalink / raw)
  To: Andreas Westin XX; +Cc: linux-kernel

On Don, 2008-03-13 at 16:09 +0100, Andreas Westin XX wrote:
[....]
> I ran checkpatch.pl on a piece of code I wrote and besides all the other
> warnings/errors it complained about a static pointer being initialised
> to NULL/0. I fixed it but I'm curious as to why this is not permitted ?

Because "uninitialized" data is automatically initialized wit 0. An
explicit initialization with 0/NULL wastes space in the kernel image.

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: checkpatch.pl and statics
  2008-03-13 15:43 ` Bernd Petrovitsch
@ 2008-03-16 13:34   ` Benny Halevy
  2008-03-16 14:13     ` Bernd Petrovitsch
  0 siblings, 1 reply; 5+ messages in thread
From: Benny Halevy @ 2008-03-16 13:34 UTC (permalink / raw)
  To: Bernd Petrovitsch; +Cc: Andreas Westin XX, linux-kernel

On Mar. 13, 2008, 17:43 +0200, Bernd Petrovitsch <bernd@firmix.at> wrote:
> On Don, 2008-03-13 at 16:09 +0100, Andreas Westin XX wrote:
> [....]
>> I ran checkpatch.pl on a piece of code I wrote and besides all the other
>> warnings/errors it complained about a static pointer being initialised
>> to NULL/0. I fixed it but I'm curious as to why this is not permitted ?
> 
> Because "uninitialized" data is automatically initialized wit 0. An
> explicit initialization with 0/NULL wastes space in the kernel image.

gcc (at least version >= 4.1.2) seems to smarter than that. It
doesn't seem to put data initialized to zero in the initialized data
segment but rather adds it to the uninitialized data. That said,
initializing statically allocated data to zero is superfluous in C
and should be avoided for style/elegance reasons as well.

Benny

> 
> 	Bernd


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: checkpatch.pl and statics
  2008-03-16 13:34   ` Benny Halevy
@ 2008-03-16 14:13     ` Bernd Petrovitsch
  2008-03-16 16:23       ` Benny Halevy
  0 siblings, 1 reply; 5+ messages in thread
From: Bernd Petrovitsch @ 2008-03-16 14:13 UTC (permalink / raw)
  To: Benny Halevy; +Cc: Andreas Westin XX, linux-kernel

On Son, 2008-03-16 at 15:34 +0200, Benny Halevy wrote:
> On Mar. 13, 2008, 17:43 +0200, Bernd Petrovitsch <bernd@firmix.at> wrote:
> > On Don, 2008-03-13 at 16:09 +0100, Andreas Westin XX wrote:
> > [....]
> >> I ran checkpatch.pl on a piece of code I wrote and besides all the other
> >> warnings/errors it complained about a static pointer being initialised
> >> to NULL/0. I fixed it but I'm curious as to why this is not permitted ?
> > 
> > Because "uninitialized" data is automatically initialized wit 0. An
> > explicit initialization with 0/NULL wastes space in the kernel image.
> 
> gcc (at least version >= 4.1.2) seems to smarter than that. It

That's good news (and new to me too).

> doesn't seem to put data initialized to zero in the initialized data
> segment but rather adds it to the uninitialized data. That said,
> initializing statically allocated data to zero is superfluous in C
> and should be avoided for style/elegance reasons as well.

Well, one can discuss endlessly about style and elegance ....

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: checkpatch.pl and statics
  2008-03-16 14:13     ` Bernd Petrovitsch
@ 2008-03-16 16:23       ` Benny Halevy
  0 siblings, 0 replies; 5+ messages in thread
From: Benny Halevy @ 2008-03-16 16:23 UTC (permalink / raw)
  To: Bernd Petrovitsch; +Cc: Andreas Westin XX, linux-kernel

On Mar. 16, 2008, 16:13 +0200, Bernd Petrovitsch <bernd@firmix.at> wrote:
> On Son, 2008-03-16 at 15:34 +0200, Benny Halevy wrote:
>> On Mar. 13, 2008, 17:43 +0200, Bernd Petrovitsch <bernd@firmix.at> wrote:
>>> On Don, 2008-03-13 at 16:09 +0100, Andreas Westin XX wrote:
>>> [....]
>>>> I ran checkpatch.pl on a piece of code I wrote and besides all the other
>>>> warnings/errors it complained about a static pointer being initialised
>>>> to NULL/0. I fixed it but I'm curious as to why this is not permitted ?
>>> Because "uninitialized" data is automatically initialized wit 0. An
>>> explicit initialization with 0/NULL wastes space in the kernel image.
>> gcc (at least version >= 4.1.2) seems to smarter than that. It
> 
> That's good news (and new to me too).
> 
>> doesn't seem to put data initialized to zero in the initialized data
>> segment but rather adds it to the uninitialized data. That said,
>> initializing statically allocated data to zero is superfluous in C
>> and should be avoided for style/elegance reasons as well.
> 
> Well, one can discuss endlessly about style and elegance ....

Heh, that's what checkpatch is all about, isn't it? :)
Real errors and warnings should be caught and reported by the compiler...

Benny

> 
> 	Bernd


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-03-16 16:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-13 15:09 checkpatch.pl and statics Andreas Westin XX
2008-03-13 15:43 ` Bernd Petrovitsch
2008-03-16 13:34   ` Benny Halevy
2008-03-16 14:13     ` Bernd Petrovitsch
2008-03-16 16:23       ` Benny Halevy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox