9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Winston Kodogo <kodogo@gmail.com>
To: 9fans@9fans.net
Subject: [9fans] C question - completely OT, but I'd like to know the answer
Date: Thu,  8 Sep 2011 21:41:05 +1200	[thread overview]
Message-ID: <CAFiGbxi4tuz18VvmnEXe2fxcRaSn3UfVJJwMXuEi-tC6=rrK2Q@mail.gmail.com> (raw)

Sorry to bother the list, but I thought I might get a sensible answer
here from the few remaining people in the world who actually
understand C.

The following bit of code seems to be more or less syntactically OK:

switch (nurdge)
{
    int nigel = 1;
    case 0:
		if(nigel == 1)
			printf("nigel is one.\n");
		else
			printf("nigel is not one.\n");

	default:
		printf("The value of nigel is %d", nigel);
}

Something close to this compiles under my C compiler, and yet the
variable "nigel" is not initialised, and the test inside the first
case test is pretty much certain to print "nigel is not one". Although
my C++ compiler does complain about an uninitialised variable.

I'm puzzled as to why the line "int nigel = 1;" is syntactically OK,
and although it seems to have declared the variable "nigel" - else the
following code would fail to compile - has failed to give it the
initial value of 1, as requested.



             reply	other threads:[~2011-09-08  9:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-08  9:41 Winston Kodogo [this message]
2011-09-08  9:57 ` dexen deVries
2011-09-08 10:44 ` dexen deVries

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='CAFiGbxi4tuz18VvmnEXe2fxcRaSn3UfVJJwMXuEi-tC6=rrK2Q@mail.gmail.com' \
    --to=kodogo@gmail.com \
    --cc=9fans@9fans.net \
    /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;
as well as URLs for NNTP newsgroup(s).