Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #3756
| From | George Neuner <gneuner2@comcast.net> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: A tiny self-hosting compiler used for teaching |
| Date | 2026-09-05 14:02 -0400 |
| Organization | Compilers Central |
| Message-ID | <26-09-004@comp.compilers> (permalink) |
| References | <26-08-007@comp.compilers> |
On Tue, 25 Aug 2026 08:05:06 +0200, Michael Lehn
<michael.lehn@uni-ulm.de> wrote:
>The main motivation for A Better C is actually quite mundane. When teaching C,
>I always found declarations unnecessarily difficult to explain. For example:
>
> int *a[10]; // array of 10 pointers to int
> int (*b)[10]; // pointer to an array of 10 ints
>
>There is a perfectly consistent logic behind C declarations: you declare an
>object in a form resembling how it is used. But for beginners this means that
>they already need to understand operator precedence — in particular that
>postfix operators bind more strongly than prefix operators — just to read a
>declaration.
>
>I learned Pascal before C myself, and always found Pascal declarations easier
>to read because you can essentially read them from left to right.
I also learned Pascal before C, and I always have preferred
Pascal-like syntax to the line noise that is typical of C. Ironically
most of my career was spent using C++, SQL and Scheme.
IMO, the main reasons that Pascal declarations were easier are:
1) variable names are not intermixed with their types
2) complex types generally require one or more type declarations
and can't be declared inline in a variable declaration
WRT your examples (and ignoring array base issues), in Pascal the
array of pointers is no problem /because/ the base type of the array
is simple, however the pointer to array can't be declared in one step
because the array itself is not a simple type.
type
tenInts = array [1..10] of integer;
var
a : array [1..10] of ^integer; { array of 10 pointers to int }
b : ^tenInts; { pointer to array of 10 ints }
Yes, reading the declaration for 'b', you do have to go search out the
declaration of 'tenInts', but what you don't have to do is decipher a
string of line noise to understand the type.
Of course, in C you could typedef the array and declare 'b' as a
pointer to it - but most programmers would never think to do that with
such a "simple" declaration. Few even would bother declaring 'b' a
"pointer to array of int" when "pointer to int" will work just as
well.
[ignoring potential for error checking by the compiler.]
And, of course, if you want a Pascal-like language with more
functional parity to C there were/are extended and OO Pascals, and
derivatives like Modula 2, 2+, 3, etc.
>That is almost the whole idea behind A Better C: it is basically C, but with
>declarations following a Pascal-like logic. Since `^` already has a meaning in
>C, I used `->` for pointers.
Yeah ... but what do the declarations look like? Unless you totally
changed the syntax, just changing what token(s) denote a "pointer" or
a "dereference" operation is no more helpful than is the original C.
YMMV.
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: A tiny self-hosting compiler used for teaching Michael Lehn <michael.lehn@uni-ulm.de> - 2026-08-25 08:05 +0200
Re: A tiny self-hosting compiler used for teaching Cóilín Nioclásín Glostéir <thanks-to@Taf.com> - 2026-09-04 21:12 +0000
Re: A tiny self-hosting compiler used for teaching ram@zedat.fu-berlin.de - 2026-09-05 07:02 +0000
Re: A tiny self-hosting compiler used for teaching Michael Lehn <michael.lehn@uni-ulm.de> - 2026-09-05 19:47 -0700
Re: A tiny self-hosting compiler used for teaching George Neuner <gneuner2@comcast.net> - 2026-09-05 14:02 -0400
Re: A tiny self-hosting compiler used for teaching Michael Lehn <michael.lehn@uni-ulm.de> - 2026-09-05 19:50 -0700
Re: A tiny self-hosting compiler used for teaching ram@zedat.fu-berlin.de - 2026-09-05 07:02 +0000
Re: A tiny self-hosting compiler used for teaching George Neuner <gneuner2@comcast.net> - 2026-09-05 14:02 -0400
Re: A tiny self-hosting compiler used for teaching George Neuner <gneuner2@comcast.net> - 2026-09-07 15:23 -0400
Re: A tiny self-hosting compiler used for teaching Michael Lehn <michael.lehn@me.com> - 2026-09-05 22:58 -0700
csiph-web