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.
"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".
No. "auto" is not a type but a storage class that means automatically allocated instead of being allocated to a register, extern-al to the file, or in the static code segment.
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.
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.
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 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.
The question of if the first C compiler was written in C, how could it be the first C Compiler?
Because to be the first, it has to be bootstrapped in an intermediate host language…
You have to get a parser running, then the syntax, then the etc… etc…
( immense plug of the Ahl book here…)
To be the first complier in a language, as was pointed out, long before I was born,
the compiler has to compile itself, so before it could compile itself, it had to have other language processing programs creating the parsing, the syntax, the etc…
Porting it to GCC just means that they could compile it with GCC, the big test is to get it to compile itself, on what ever platform that is the target platform, because finally, if it cannot generate object code/machine language in the target machine’s binary, then its not really ported.
Later on, UNIX came with tools to build compilers with, YACC and LEX.
If they got it to produce PDP-7 Code, its not really much of a port, really.
[+] [-] ggm|5 years ago|reply
[+] [-] st_goliath|5 years ago|reply
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':
[+] [-] sgtnoodle|5 years ago|reply
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.
[+] [-] raverbashing|5 years ago|reply
Edit: it doesn't blow up, not even with -Wall and -std=c99
[+] [-] nspain|5 years ago|reply
[+] [-] dvko|5 years ago|reply
[+] [-] burstmode|5 years ago|reply
[+] [-] 1ris|5 years ago|reply
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.
[+] [-] bawolff|5 years ago|reply
[+] [-] layoutIfNeeded|5 years ago|reply
[+] [-] captainmuon|5 years ago|reply
The type is not given at all, I think by default it would be "int".
[+] [-] IncRnd|5 years ago|reply
[+] [-] unknown|5 years ago|reply
[deleted]
[+] [-] Taniwha|5 years ago|reply
[+] [-] vesinisa|5 years ago|reply
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.
[+] [-] nils-m-holm|5 years ago|reply
[+] [-] 29athrowaway|5 years ago|reply
[+] [-] dvt|5 years ago|reply
† 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
[+] [-] onei|5 years ago|reply
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.
[+] [-] Nicksil|5 years ago|reply
https://en.wikipedia.org/wiki/Bootstrapping_(compilers)
[+] [-] IncRnd|5 years ago|reply
[+] [-] ForOldHack|5 years ago|reply
Because to be the first, it has to be bootstrapped in an intermediate host language… You have to get a parser running, then the syntax, then the etc… etc…
( immense plug of the Ahl book here…)
To be the first complier in a language, as was pointed out, long before I was born, the compiler has to compile itself, so before it could compile itself, it had to have other language processing programs creating the parsing, the syntax, the etc…
Porting it to GCC just means that they could compile it with GCC, the big test is to get it to compile itself, on what ever platform that is the target platform, because finally, if it cannot generate object code/machine language in the target machine’s binary, then its not really ported.
Later on, UNIX came with tools to build compilers with, YACC and LEX.
If they got it to produce PDP-7 Code, its not really much of a port, really.
[+] [-] pabs3|5 years ago|reply
[+] [-] unknown|5 years ago|reply
[deleted]
[+] [-] polska|5 years ago|reply
[+] [-] vkoskiv|5 years ago|reply