Live data from Hacker News

First C compiler ported to GCC

github.com

31–40 of 90 posts

Re: First C compiler ported to GCC

#31
post #21

The a[b] implemented as *(a+b) Thing, is how we were taught to think about array indexing in the CS lectures of the 70s

And that's how it's still taught nowadays.

Both the C89 and the C99 standard draft contain the following:

> The definition of the subscript operator [] is that E1[E2] is identical to (*((E1)+(E2)))

In fact the expressions a[b] *(a + b) and b[a] are equivalent.

Here is a perfectly valid snippet of C code that will print out 't':

    putchar(3["test"]);

Re: First C compiler ported to GCC

#32
post #14

Earlier quoted context omitted.

Bootstrapping https://en.wikipedia.org/wiki/Bootstrapping_(compilers)

If it could bootstrap itself, then there would be no need to port it to GCC . From how I read it, it is not capable of bootstrapping itself, and an earlier C compiler in BCPL existed, this is the first C compiler written in C itself.

this port is [optionally] a cross compiler - it will run on x86/arm/whatever and produce pdp11 assembly

on an actual pdp11 it CAN bootstrap

Re: First C compiler ported to GCC

#34
post #21

The a[b] implemented as *(a+b) Thing, is how we were taught to think about array indexing in the CS lectures of the 70s

Hence why it "can be written" as b[a] as well Edit: it doesn't blow up, not even with -Wall and -std=c99

It will not “blow up” in modern compilers, nor can it, because that’s _how the operator is defined_.

Re: First C compiler ported to GCC

#35
post #21

The a[b] implemented as *(a+b) Thing, is how we were taught to think about array indexing in the CS lectures of the 70s

Hence why it "can be written" as b[a] as well Edit: it doesn't blow up, not even with -Wall and -std=c99

> (yes it will probably blow up in modern compilers, or at least give you a warning)

Nope. For the code snippet I posted an hour ago, even with -pedantic -Wall -Wextra gcc won't issue any warnings. And why should it? It's perfectly standards conformant, because the standard actually defines the [] operator through the equivalent addition expression.

Re: First C compiler ported to GCC

#37
post #9

Earlier quoted context omitted.

"auto" probably is the storage class, it tells what kind of variable this is. Automatic as opposed to "register" which would force the variable to be a register, or "static" or "extern". The type is not given at all, I think by default it would be "int".

One of the unusual things in this early version of C is that "int" can be used for any word-sized value, including pointers. The type system was very loose.

Even back then this was considered poor practice, however. The first edition of K&R had a subsection entitled "Pointers are Not Integers" (I don't know if that's still in modern editions).

Re: First C compiler ported to GCC

#38

Earlier quoted context omitted.

Hence why it "can be written" as b[a] as well Edit: it doesn't blow up, not even with -Wall and -std=c99

> (yes it will probably blow up in modern compilers, or at least give you a warning) Nope. For the code snippet I posted an hour ago, even with -pedantic -Wall -Wextra gcc won't issue any warnings. And why should it? It's perfectly standards conformant, because the standard actually defines the [] operator through the equivalent addition expression.

> why should it?

It's extremely poor style, even if the behaviour is identical.

Re: First C compiler ported to GCC

#40

Earlier quoted context omitted.

> (yes it will probably blow up in modern compilers, or at least give you a warning) Nope. For the code snippet I posted an hour ago, even with -pedantic -Wall -Wextra gcc won't issue any warnings. And why should it? It's perfectly standards conformant, because the standard actually defines the [] operator through the equivalent addition expression.

> why should it? It's extremely poor style, even if the behaviour is identical.

So you expect to compiler to give you style points for your code?

To be clear: it isn't just coincidentally identical behaviour, it is defined by the standard to be equivalent.

Post reply on HN