I do not understand why we should create a C compiler ported to GCC.
Not a C compiler. This is the original C compiler from ~1972. It's just an experiment to bring a bit of computing history to life.
First C compiler ported to GCC
41–50 of 90 posts
Re: First C compiler ported to GCC
#42The 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
#43Earlier quoted context omitted.
> 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.
Re: First C compiler ported to GCC
#44Earlier quoted context omitted.
> 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.
Fortunately compilers already do this. GCC will warn you about unused variables, for instance.
Re: First C compiler ported to GCC
#45Earlier quoted context omitted.
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
#46The 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
#47Earlier quoted context omitted.
> 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.
Re: First C compiler ported to GCC
#48The 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
#49Earlier 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.
Re: First C compiler ported to GCC
#50Earlier quoted context omitted.
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.
Most compilers will warn about misleading indentation. This is misleading indexing. A program containing misleading indentation is also standards-compliant, but that's completely irrelevant when talking about what code should trigger warnings.