Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #3760
| From | Michael Lehn <michael.lehn@uni-ulm.de> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: A tiny self-hosting compiler used for teaching |
| Date | 2026-09-05 19:50 -0700 |
| Organization | Compilers Central |
| Message-ID | <26-09-008@comp.compilers> (permalink) |
| References | <26-09-004@comp.compilers> |
> On 5. Sep 2026, at 17:18, George Neuner <gneuner2@comcast.net> wrote:
> 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. ...
Yes, I did totally change the declaration syntax. That is the point. :-)
The two declarations look like this in ABC:
a: array[10] of -> int;
b: -> array[10] of int;
Thus, `a` is an array of ten pointers to integers, whereas `b` is a pointer to
an array of ten integers.
The variable name is separated from its type, and the type itself can be read
from left to right. `->` is a prefix type constructor, rather than merely a
replacement for `*` within C’s declaration syntax. No parentheses or knowledge
of expression-operator precedence are required to distinguish the two types.
The same principle also applies to more complicated types. For example:
f: -> fn();
g: -> fn(value: int);
h: -> fn(value: int): int;
declare pointers to functions with increasingly detailed parameter and return
types.
ABC is not intended to suggest that Pascal, Modula-2, or related languages did
not already solve this problem. Quite the opposite: it deliberately preserves
their clearer declaration logic while retaining C-like expressions and a low-
level programming model.
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