9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] C99 and you
@ 2006-10-05 18:32 Skip Tavakkolian
  2006-10-06  0:09 ` Bruce Ellis
  0 siblings, 1 reply; 6+ messages in thread
From: Skip Tavakkolian @ 2006-10-05 18:32 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 456 bytes --]

somebody had a question a couple of days ago.  i wonder if the declaration
was inside a switch or after a label?

in the example below, if the seemingly superfluous ';' (comments 1, and 2)
are removed, it is a syntax error.  also note the scope of the declaration
inside a switch (e.g. when argc==1)

explanation:	http://www.thescripts.com/forum/thread214730.html
reference: 	http://wwwold.dkuug.dk/jtc1/sc22/open/n2794/n2794.txt	(look for A.2.3)

[-- Attachment #2: c99test.c --]
[-- Type: text/plain, Size: 315 bytes --]

#include <u.h>
#include <libc.h>

main(int argc, char **argv)
{
	int i;

	switch (argc) {
	case 2:
		;	// 1
		int j = 1;
		print("argc = %d; j = %d\n", argc, j);
		break;
	case 1:
		j = 0;
		print("argc = %d; j = %d\n", argc, j);
		break;
	}

	int k;

 foo:
	;	// 2
	int l;

	exits(nil);
}

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

* Re: [9fans] C99 and you
  2006-10-05 18:32 [9fans] C99 and you Skip Tavakkolian
@ 2006-10-06  0:09 ` Bruce Ellis
  2006-10-06  1:33   ` Skip Tavakkolian
  2006-10-06  8:28   ` Charles Forsyth
  0 siblings, 2 replies; 6+ messages in thread
From: Bruce Ellis @ 2006-10-06  0:09 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

if that is the case i would suggest the grammar (yacc file) needs
a tweak - could be as simple as a missing case (or two).
good catch.

brucee

On 10/6/06, Skip Tavakkolian <9nut@9netics.com> wrote:
> somebody had a question a couple of days ago.  i wonder if the declaration
> was inside a switch or after a label?

etc.


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

* Re: [9fans] C99 and you
  2006-10-06  0:09 ` Bruce Ellis
@ 2006-10-06  1:33   ` Skip Tavakkolian
  2006-10-06  8:28   ` Charles Forsyth
  1 sibling, 0 replies; 6+ messages in thread
From: Skip Tavakkolian @ 2006-10-06  1:33 UTC (permalink / raw)
  To: 9fans

> if that is the case i would suggest the grammar (yacc file) needs
> a tweak - could be as simple as a missing case (or two).
> good catch.

from what i understand, compiler is following the
spec.  i don't know why the spec is that way.



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

* Re: [9fans] C99 and you
  2006-10-06  0:09 ` Bruce Ellis
  2006-10-06  1:33   ` Skip Tavakkolian
@ 2006-10-06  8:28   ` Charles Forsyth
  2006-10-06  9:51     ` erik quanstrom
  1 sibling, 1 reply; 6+ messages in thread
From: Charles Forsyth @ 2006-10-06  8:28 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 470 bytes --]

based on the grammar snippet posted earlier, it looks as though
the compiler is correct.  a case label in C is not so different from a label
(thus duff's device is allowed), and as i understood the snippet,
declarations can't be labelled.  might make you wonder why they
bothered, and indeed, i do wonder.  i think they should leave the language alone.
(and if they were going to do more than tinker,
they might have added something significant, such as tuples.)

[-- Attachment #2: Type: message/rfc822, Size: 3269 bytes --]

From: "Bruce Ellis" <bruce.ellis@gmail.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: [9fans] C99 and you
Date: Fri, 6 Oct 2006 10:09:20 +1000
Message-ID: <775b8d190610051709g5f9a66f5tc9c387315bc94d86@mail.gmail.com>

if that is the case i would suggest the grammar (yacc file) needs
a tweak - could be as simple as a missing case (or two).
good catch.

brucee

On 10/6/06, Skip Tavakkolian <9nut@9netics.com> wrote:
> somebody had a question a couple of days ago.  i wonder if the declaration
> was inside a switch or after a label?

etc.

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

* Re: [9fans] C99 and you
  2006-10-06  8:28   ` Charles Forsyth
@ 2006-10-06  9:51     ` erik quanstrom
  2006-10-06 16:00       ` Bruce Ellis
  0 siblings, 1 reply; 6+ messages in thread
From: erik quanstrom @ 2006-10-06  9:51 UTC (permalink / raw)
  To: 9fans

actually, the switch statement here is a red herring.  here's what kenc dislikes:

	label:	int assignment = 0;

so this will generate an error, too:

void
main(void)
{
begin:	int j;
	j = 0;
	if(j>1)
		goto begin;
	exits("");
}

gcc is also unable to parse this production.  

- erik


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

* Re: [9fans] C99 and you
  2006-10-06  9:51     ` erik quanstrom
@ 2006-10-06 16:00       ` Bruce Ellis
  0 siblings, 0 replies; 6+ messages in thread
From: Bruce Ellis @ 2006-10-06 16:00 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

sorry, i misunderstood the absurd standard, again.

brucee

On 10/6/06, erik quanstrom <quanstro@quanstro.net> wrote:
> actually, the switch statement here is a red herring.  here's what kenc dislikes:
>
>        label:  int assignment = 0;
>
> so this will generate an error, too:
>
> void
> main(void)
> {
> begin:  int j;
>        j = 0;
>        if(j>1)
>                goto begin;
>        exits("");
> }
>
> gcc is also unable to parse this production.
>
> - erik
>


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

end of thread, other threads:[~2006-10-06 16:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-05 18:32 [9fans] C99 and you Skip Tavakkolian
2006-10-06  0:09 ` Bruce Ellis
2006-10-06  1:33   ` Skip Tavakkolian
2006-10-06  8:28   ` Charles Forsyth
2006-10-06  9:51     ` erik quanstrom
2006-10-06 16:00       ` Bruce Ellis

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).