a[b] implemented as *(a+b)
Thing, is how we were taught to think about array indexing in the CS lectures of the 70sFirst C compiler ported to GCC
21–30 of 90 posts
Re: First C compiler ported to GCC
#22The a[b] implemented as *(a+b) Thing, is how we were taught to think about array indexing in the CS lectures of the 70s
I imagine there are more optimal and less optimal ways of actually doing the indexing in machine code and the former may be better semantics, but I would think a compiler would generate identical machine code for both.
Re: First C compiler ported to GCC
#23If the first C compiler was written in C... how could it be first C compiler? How could you compile the first C compiler?
C was heavily inspired by B and I suspect written in B aswell. Alternatively, BCPL was extremely portable as it compiled to OCode (what we'd recognise today as bytecode) so that might have been another option. The assignment operators of =+ are straight from B and later changed to += due to Dennis Ritchie's personal taste.
Re: First C compiler ported to GCC
#24"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
#25The a[b] implemented as *(a+b) Thing, is how we were taught to think about array indexing in the CS lectures of the 70s
Are those not equivalent expressions in modern C? I imagine there are more optimal and less optimal ways of actually doing the indexing in machine code and the former may be better semantics, but I would think a compiler would generate identical machine code for both.
Re: First C compiler ported to GCC
#26Earlier quoted context omitted.
Are those not equivalent expressions in modern C? I imagine there are more optimal and less optimal ways of actually doing the indexing in machine code and the former may be better semantics, but I would think a compiler would generate identical machine code for both.
I’m pretty sure you have to take the size of the objects in mind.
The size of the objects is implicitly taken into account by the compiler, it knows the size of the objects by the type of the pointer.
Re: First C compiler ported to GCC
#27The a[b] implemented as *(a+b) Thing, is how we were taught to think about array indexing in the CS lectures of the 70s
Re: First C compiler ported to GCC
#28Earlier quoted context omitted.
Are those not equivalent expressions in modern C? I imagine there are more optimal and less optimal ways of actually doing the indexing in machine code and the former may be better semantics, but I would think a compiler would generate identical machine code for both.
I’m pretty sure you have to take the size of the objects in mind.
Re: First C compiler ported to GCC
#29If the first C compiler was written in C... how could it be first C compiler? How could you compile the first C compiler?
The very first B compiler was written in BCPL by Ken Thompson. B later became self-hosting, i.e. the BCPL compiler compiled the B compiler, but this had another set of challenges due to the extreme memory constraints. It was an iterative process where a new feature was added such that it pushed the memory limit and then the compiler was rewritten to use the new feature to bring the memory usage down. C was heavily in…
Re: First C compiler ported to GCC
#30"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.