mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Peterson <joe@skyrush.com>
To: Cong Wang <amwang@redhat.com>
Cc: Alan Cox <alan@linux.intel.com>,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: Re: [Patch] tty: move a definition out of switch block
Date: Thu, 3 Dec 2009 08:18:11 -0700	[thread overview]
Message-ID: <fd3b2d10912030718q30176616r1ac3b71a4399fc0b@mail.gmail.com> (raw)
In-Reply-To: <4B177878.2090002@redhat.com>

On Thu, Dec 3, 2009 at 01:36, Cong Wang <amwang@redhat.com> wrote:
> Generally putting variables local in the local scope is fine, but
> not for 'switch' block, to be more precisely, not for the case
> where putting local variables between 'switch' and its _first_
> label, IMO.

It is fine to declare variables at the start of a switch statement.
What *is* incorrect is either initializing such declared variables
(they won't get initialized) or declaring variables *after* a case
label (throws a compile error).

> It can lead to misunderstanding easily, since 'switch'
> jumps to its first label at a first glance. I know in this case
> the code is _not_ wrong, but again, it's not good for reading.

I would think the declaration inside the start of the switch block
would just indicate to the reader that the variable is local to the
switch block scope.

> Also, there's no conflicts if we put it out of 'switch' block.

But then the scope of these variables becomes larger than it need be.

-Joe

      parent reply	other threads:[~2009-12-03 15:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-01  7:54 Amerigo Wang
2009-12-01 15:44 ` Alan Cox
2009-12-03  8:36   ` Cong Wang
2009-12-03 11:13     ` Alan Cox
2009-12-08 10:10       ` Cong Wang
2009-12-08 15:02         ` Joe Peterson
2009-12-03 15:18     ` Joe Peterson [this message]

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=fd3b2d10912030718q30176616r1ac3b71a4399fc0b@mail.gmail.com \
    --to=joe@skyrush.com \
    --cc=akpm@linux-foundation.org \
    --cc=alan@linux.intel.com \
    --cc=amwang@redhat.com \
    --cc=gregkh@suse.de \
    --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®