mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Al Viro <viro@parcelfarce.linux.theplanet.co.uk>
To: Pekka J Enberg <penberg@cs.helsinki.fi>
Cc: Anton Altaparmakov <aia21@cam.ac.uk>,
	linux-ntfs-dev@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: ntfs: remove redundant assignments
Date: Thu, 26 May 2005 08:04:38 +0100	[thread overview]
Message-ID: <20050526070437.GY29811@parcelfarce.linux.theplanet.co.uk> (raw)
In-Reply-To: <courier.42956AFA.00002502@courier.cs.helsinki.fi>

On Thu, May 26, 2005 at 09:21:46AM +0300, Pekka J Enberg wrote:
> On Wed, 2005-05-25 at 22:10 +0100, Anton Altaparmakov wrote:
> >This is not.  memset(0) is not the same as = NULL IMO.  I don't care if 
> >the compiler thinks it is the same.  NULL does not have to be 0 so I 
> >prefer to initialize pointers explicitly to NULL.  Even more so since this 
> >code is not performance critical at all so I prefer clarity here.
> 
> I kind of figured out you were doing it on purpose. The fact is, NULL is 
> zero on _all_ Linux architectures. If it weren't, we'd have a lot of broken 
> code. Let me play the devils advocate here: why do you memset() (now 
> kcalloc()) in the first place? 

Oh, come on...

	ictx = kmalloc(sizeof(ntfs_index_context), GFP_NOFS);
	if (ictx)
		*ictx = (ntfs_index_context){.idx_ni = idx_ni};
	return ictx;

and be done with that.  Let compiler do its job.  And yes, that *will*
give properly initialized pointers even for weird platforms.  Not that
we had the slightest chance of porting to any of them...

> There's a simple reason why I don't like explicit assignments: it's way too 
> easy to forget to initialize something. 

So use the proper constructs.  Variant above is guaranteed to do the right
thing on any C99 compiler, provided that kmalloc() returns NULL or pointer
to object sufficiently large and properly aligned for ntfs_index_context.
All missing fields will be initialized the same way they would for initializer
of a static object.

  reply	other threads:[~2005-05-26  7:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1117044875.9510.2.camel@localhost>
     [not found] ` <Pine.LNX.4.60.0505252208120.25834@hermes-1.csi.cam.ac.uk>
2005-05-26  6:21   ` Pekka J Enberg
2005-05-26  7:04     ` Al Viro [this message]
2005-05-26  8:14       ` [PATCH] ntfs: use struct initializers Pekka J Enberg
2005-05-27 15:45         ` Anton Altaparmakov
2005-05-26  8:39       ` ntfs: remove redundant assignments cutaway
2005-05-27 15:04       ` Anton Altaparmakov

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=20050526070437.GY29811@parcelfarce.linux.theplanet.co.uk \
    --to=viro@parcelfarce.linux.theplanet.co.uk \
    --cc=aia21@cam.ac.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ntfs-dev@lists.sourceforge.net \
    --cc=penberg@cs.helsinki.fi \
    /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®