Live data from Hacker News

First C compiler ported to GCC

github.com

11–20 of 90 posts

Re: First C compiler ported to GCC

#12

If the first C compiler was written in C... how could it be first C compiler? How could you compile the first C compiler?

The first (or proto) C compiler was written in B†[1] (called NB, or New B). This is the first C compiler written in C.

† Or maybe some variant of BCPL -- I'm not exactly sure how functionally different the two were.

[1] https://www.bell-labs.com/usr/dmr/www/chist.html

Re: First C compiler ported to GCC

#15
post #11

"The compiler runs only in 32 bit mode as the original code assumes that the pointer size and word size are the same." ... which was um, 16-bits

Yes, and on 16-bit and 32-bit systems, sizeof(int) == sizeof(int*). On 64-bit systems, this is most probably not the case. This is a common roadblock when porting old C programs.

Re: First C compiler ported to GCC

#16
post #11

"The compiler runs only in 32 bit mode as the original code assumes that the pointer size and word size are the same." ... which was um, 16-bits

I think he means that int and pointer address must be interchangeable. As long as that holds, the size can be either 16 bits or 32 bits.

On a PDP-11 int would have been 16-bit. On x86 32 bits. But on x86_64 int is 32 bits but pointers are 64-bit. The easiest way to retain the original assumption with minimal changes to the historical source code while targeting a modern CPU is to compile in 32-bit mode.

Re: First C compiler ported to GCC

#17
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.

> types of the function parameters are not checked, anything can be passed to any function

Still a better type system than Twilight.

Re: First C compiler ported to GCC

#18
post #14

If the first C compiler was written in C... how could it be first C compiler? How could you compile the first C compiler?

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.

Re: First C compiler ported to GCC

#20
post #7

Did this compiler really support "auto" as a variable type, as seen in example fizzbuzz ?

"auto" in c is a storage class specifier, like "register", "extern" or "static". https://en.cppreference.com/w/c/language/storage_duration It was considered pretty useless by most, so c++11 recycled the keyword to mean something different.

See also: https://www.seebs.net/faqs/c-iaq.html#question-1.8
Post reply on HN