🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4302

Re: Grammar for Switch Statement

#4302
From: Peter Seebach
Date: Sun, 29 Oct 1995 23:47
44 lines
1519 bytes
In article <470ih7$mvh@gaia.ns.utk.edu>,
Eric Lemings <elemings@unix1.utm.edu> wrote:
>Why is the grammar specification for a 'switch' statement:

>	switch ( expression ) statement

>instead of:

>	switch ( expression ) block

A block is a kind-of-a statement.  But the key is that you do not need
the {}'s if there is only one case and one statement.

For instance: (One of my entries in IOCCC.)

#include <stdio.h>
#include <stdlib.h>

int
main(int c, char *v[])
{
	char *f = "Hello, world!";
	switch (c)
	case 2:
		switch (*v[1] ^ '-')
		case 0:
			switch (*(v[1] + 1) ^ 't')
			case 0:
				f = "hello, world!";
	((c > 2) || ((c > 1) && !(*v[1] ^ '-') && *(v[1] + 1) ^ 't')) &&
		(puts("usage: hello [-h|-t]"),
		 exit(((c > 2) || (*v[1] ^ '-') ||
			(*(v[1] + 1) ^ 'h') || (*(v[1] + 2))) ?
			EXIT_FAILURE : EXIT_SUCCESS), 1);
	puts(f);
	return 0;
}

-s
-- 
Peter Seebach - seebs@solon.com || seebs@intran.xerox.com --
C/Unix proto-wizard -- C/Unix questions? Send mail for help.  No, really!
Copyright 1995 Peter Seebach.  --  High energy particle theology
The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq
Technical Details
Message-ID: <4713rc$3d9@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <470ih7$mvh@gaia.ns.utk.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: seebs@solutions.solon.com (Peter Seebach)
Newsgroups: comp.std.c
Subject: Re: Grammar for Switch Statement
Date: 29 Oct 1995 17:47:56 -0600
Organization: Usenet Fact Police (Undercover)
Message-ID: <4713rc$3d9@solutions.solon.com>
References: <470ih7$mvh@gaia.ns.utk.edu>
NNTP-Posting-Host: solutions.solon.com