🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #608

Re: Taming The Switch-Statement

#608
From: bart
Date: Tue, 20 Oct 2026 14:11
161 lines
7258 bytes
On 20/10/2026 02:03, Waldek Hebisch wrote:
> bart <bc@freeuk.com> wrote:
>>
>> OK. But they HAD to create C? There were quite a few languages in the
>> early 70s too: like Pascal, Fortran, PL/I, Coral-66, plus of course BCPL
>> and B. So why a new one?
> 
> You ignore fact that Ritche wanted reasonably fast code from
> very simple compiler.

According to DC's quote from HOPL, it was also more fun to create a new 
language.


> PL/I had most needed features.  But PL/I was a big language,
> to run on small machine they would have to take tiny subset
> and then add extentions.  Basicaly they would end up with a
> language which is very far from PL/I.

There were PL/360 and PL/M, although those were more specific, more 
'machine-oriented' languages. (I implemented one for PDP10 but it was a 
port of a systems language from a GEC machine.)

Anyway, a more general subset could have been used.


> Similarly, BCPL was too complicated, B and C were simplifications
> and adaptations small machine.
> 
> I think that Pascal was too late: nominally it was created earlier
> but I think that it was available to Bell Labs only after they
> did initial work leading to C.  And Pascal shared problem of
> speed on small machines.  Note that later UCSD Pascal which
> run on micros compiled to interpreted bytecode, which significantly
> reduced performance.

It would not have been hard to use Pascal as a starting point for a 
workable systems language. Wirth wouldn't have approved, but his 
languages were too pure, too academic; some of us had things we needed 
to get done!

Here I mean adapting Pascal for a competing systems language.

In my hands some aspects would be simplified (eg. no nested functions, 
no closures), thus making it easier to generate decent code with a 
simple compiler.


> 
>> FORTRAN syntax looked nothing like C! Unless you mean the general
>> pattern of 'INTEGER A, B' which was shared by half of all languages.
> 
> I think more pattern of
> 
> INTEGER A(20), B
> 
> which has similar structure to C variable declarations.

OK. That was typical for the time. But in Fortran it didn't get much 
more complicated than that. Maybe 2D arrays and so on.

>  Of course,
> FORTRAN had no pointers (and structures or unions), so Ritche had
> to invent syntax for them.

There were three languages from that era that I know had pointers or 
references, and which allowed composing arbitrary types with arrays and 
pointers, two of which were Algol68 and Pascal.

Both used a 100% LTR form.

The other was C. There, several choices were made:

* To start with that Fortran style except that [] are used

* To decree that that 'A[20]' syntax is supposed to match indexing of
   A as it might appear in an expression

* To introduce "*" as a prefix dereference operator in expressions ...

* ... which then means that a prefix "*" appears in the declaration too

* A further complication was to allow function pointers within that a
   declaration list

* Yet one more which came later was to add 'const', where placement now
   gets confusing

But to stay with pointers, take this expression:

    *A[i]

C precedence rules mean this is parsed as *(A[i]), which means that a 
type written as 'T *A[N]' must be an array of pointers to T (I had to 
think for a few seconds!).

But suppose you wanted a pointer to array of T? The expression for that 
would be:

     (*A)[i]

And so the declaration has to be 'T (*A)[N]' too.

So it is unfortunate that parentheses used to control precedence in an 
expression now also have to appear in type declarations (where they are 
often next to () used for parameter lists, for further confusion).

==============================================

So, what would have happened with a postfix deref op? (Ignore whether 
'*' would still be a good choice.) My first example would be this:

    A*[i]

Here, it would mean that A is dereferenced, then indexed; A must then be 
a pointer to an array of T.

But suppose we wanted the original array of pointers to T, where you 
index first then dereference. That is written like this:

    A[i]*

You simply swap the order of [] and *.

So, PARENTHESES HAVE BEEN ELIMINATED for purpose of disambiguating 
array/pointer and pointer/array, both within expressions and within 
type-declarations.

How about that? Further, most of the type-spec is now LTR; only the 
base-type has to stay on the left. Access terms in expressions will be 
fully LTR.

> IMO C suffers because typedef was added late in the game and
> function prototypes are much later.  Prototypes need types and
> to get it one needs "hole" in variable declaration.  Where the
> hole should be is specified by the C syntax, but placement of
> hole is probably least clear aspect of declarations.

I thought that 'hole' was where 'int A[10]' mean one thing in normal 
declaration but another within a parameter list.

> IMO C declaration syntax was a mistake, but as real life shows
> it was not a fatal mistake, people can adapt.

A mistake that could so easily have been avoid by choosing a different 
precedence as shown above. Did none of the thousand people working at 
Bell Labs (according to a comment in DC's follow-ip) spot this and say 
anything?

Had no-one even glanced at a Pascal spec, if there was no working copy? 
It would have transformed C type syntax.

(ACTUALLY IT IS NOT TOO LATE. A secondary postfix deref op could have 
been added. This could have been done 50 years ago, with the original 
eventually deprecated.

But this is a common theme of mine whether I perceive a problem that 
people grudgingly admit might not be idea. But nothing was ever done to 
fix it even after decades.)

Technical Details
Message-ID: <11b7sqn$32pr5$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <119qf6l$2rmg3$1@dont-email.me> <11avmfb$55rt$1@dont-email.me> <11b0cvs$skc$1@reader2.panix.com> <11b0mfv$j5ll$1@dont-email.me> <11b3r71$6me$1@reader2.panix.com> <11b500f$216c4$1@dont-email.me> <11b6ekh$d2qm$1@paganini.bofh.team>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Tue, 20 Oct 2026 15:11:35 +0100
Organization: A noiseless patient Spider
Lines: 161
Message-ID: <11b7sqn$32pr5$1@dont-email.me>
References: <119qf6l$2rmg3$1@dont-email.me> <11avmfb$55rt$1@dont-email.me>
 <11b0cvs$skc$1@reader2.panix.com> <11b0mfv$j5ll$1@dont-email.me>
 <11b3r71$6me$1@reader2.panix.com> <11b500f$216c4$1@dont-email.me>
 <11b6ekh$d2qm$1@paganini.bofh.team>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 20 Oct 2026 14:11:36 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3237733"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18u6uaO4nnRoIE7JwI1ER4A"; posting-host="7c142682e3246f1a229ef2ca48617714"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ad7c73FaDeBe8Ocw4xwti1XZRg0= sha256:qRurCrTbEJrSXWfJatXTidBfA1HNa0G7Ue67xCLE6ug=
	sha1:Sub3WoVjuEdb+BU8E6rC2T4NYis= sha256:SZ7p5WOrYADz41Z7uYooi25wfGCr8UnMWfocSEM/LiA=
In-Reply-To: <11b6ekh$d2qm$1@paganini.bofh.team>
Content-Language: en-GB