Re: A tiny self-hosting compiler used for teaching

George Neuner <gneuner2@comcast.net>
Sat, 05 Sep 2026 14:02:25 -0400

          From comp.compilers

Related articles
A tiny self-hosting compiler used for teaching michael.lehn@uni-ulm.de (Michael Lehn) (2026-08-24)
Re: A tiny self-hosting compiler used for teaching Keith.S.Thompson+u@gmail.com (Keith Thompson) (2026-08-24)
Re: A tiny self-hosting compiler used for teaching michael.lehn@uni-ulm.de (Michael Lehn) (2026-08-25)
Re: A tiny self-hosting compiler used for teaching thanks-to@Taf.com (CóilínNioclásínGlostéir) (2026-09-04)
Re: A tiny self-hosting compiler used for teaching ram@zedat.fu-berlin.de (2026-09-05)
Re: A tiny self-hosting compiler used for teaching gneuner2@comcast.net (George Neuner) (2026-09-05)
Re: A tiny self-hosting compiler used for teaching ram@zedat.fu-berlin.de (2026-09-05)
Re: A tiny self-hosting compiler used for teaching gneuner2@comcast.net (George Neuner) (2026-09-05)
Re: A tiny self-hosting compiler used for teaching michael.lehn@uni-ulm.de (Michael Lehn) (2026-09-05)
Re: A tiny self-hosting compiler used for teaching michael.lehn@uni-ulm.de (Michael Lehn) (2026-09-05)
Re: A tiny self-hosting compiler used for teaching gneuner2@comcast.net (George Neuner) (2026-09-07)
Re: A tiny self-hosting compiler used for teaching christopher.f.clark@compiler-resources.com (Christopher F Clark) (2026-09-07)
[3 later articles]
| List of all articles for this month |
From: George Neuner <gneuner2@comcast.net>
Newsgroups: comp.compilers
Date: Sat, 05 Sep 2026 14:02:25 -0400
Organization: Compilers Central
References: 26-08-007
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="32289"; mail-complaints-to="abuse@iecc.com"
Keywords: courses
Posted-Date: 05 Sep 2026 20:18:21 EDT

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.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.