News for hackers. Stuff that matters.
Re:First C compiler ported to GCC by burstmode on Wednesday April 07, 2021 @02:37AM (#26721192)
Did this compiler really support "auto" as a variable type, as seen in example fizzbuzz ?
Re:First C compiler ported to GCC by 1ris on Wednesday April 07, 2021 @02:50AM (#26721250)
"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.

Re:First C compiler ported to GCC by jwilk on Wednesday April 07, 2021 @03:43AM (#26721552)
Re:First C compiler ported to GCC by mywittyname on Wednesday April 07, 2021 @03:21PM (#26729729)
Auto is the implicit default right? As in function scoped, stack allocated, and lives until the function is returned?

K&R (Second Ed). Makes no mention of the auto keyword in Section 1.10, but it does say,

> Each local variable in a function comes into existence only when the function is called, and disappears when the function is exited. This is why such variables are usually known as automatic [sic] variables[...]

Re:First C compiler ported to GCC by 1ris on Wednesday April 07, 2021 @03:53PM (#26730237)
yes, exactly. That's why there is no need for it in modern c. This compiler however is different: The type is optional (and assumed to be int). Say you have a variable declaration "auto int i;". Back then you could omit int, now you can omit auto.
Re:First C compiler ported to GCC by bawolff on Wednesday April 07, 2021 @02:45AM (#26721232)
Auto is not a type, it means local variable. I think its still a thing, just its the default so nobody uses it.
Re:First C compiler ported to GCC by layoutIfNeeded on Wednesday April 07, 2021 @02:48AM (#26721244)
Hehe, “auto” used to mean “automatic storage” aka the stack. Then much later C++ repurposed the keyword for type deduction.
Re:First C compiler ported to GCC by captainmuon on Wednesday April 07, 2021 @02:46AM (#26721238)
"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".

Re:First C compiler ported to GCC by dvt on Wednesday April 07, 2021 @02:56AM (#26721288)
> The type is not given at all, I think by default it would be "int".

Yep, this is called the "implicit int" rule, and it was specifically outlawed[1] by C99 and onward.

[1] https://herbsutter.com/2015/04/16/reader-qa-why-was-implicit...

Re:First C compiler ported to GCC by ufo on Wednesday April 07, 2021 @02:56AM (#26721289)
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.
Re:First C compiler ported to GCC by Turing_Machine on Wednesday April 07, 2021 @06:42AM (#26722944)
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 by LukeShu on Wednesday April 07, 2021 @01:06PM (#26727704)
It looks to me like that section was removed in the 2nd edition. Some sections moved around, so maybe I'm just looking in the wrong place, but it's not nestled between "5.5 Character Pointers and Functions" and "5.7 Multi-Dimensional Arrays" like it is in the 1st edition.
Re:First C compiler ported to GCC by ufo on Wednesday April 07, 2021 @12:09PM (#26726949)
The interesting thing for me is that a variable without a type annotation could potentially store anything. It kind of explains why the language used "int" as the default type of variables declared without a type annotation.
Re:First C compiler ported to GCC by rbanffy on Wednesday April 07, 2021 @07:07AM (#26723157)
Now I want a float to access individual bits.
Re:First C compiler ported to GCC by Blikkentrekker on Wednesday April 07, 2021 @03:18AM (#26721399)
> 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 by IncRnd on Wednesday April 07, 2021 @10:15AM (#26725272)
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.