Live data from Hacker News

Dennis Ritchie's first C compiler on Github

github.com

71–80 of 88 posts

Re: Dennis Ritchie's first C compiler on Github

#71
post #57

I don't understand this main(argc, argv) int argv[]; { Is that still valid today?

I remember being absolutely thrilled when function prototypes were introduced with the 'proposed' ANSI C standard (X3J11). The first implementation I got my hands on was Borland's Turbo C circa 1988.

The standard now known as C89/C90 had been in committee for many years before being 'released'. This didn't stop the tool vendors (like Borland) from supporting the 'proposed' standard much earlier than 1989.

Unfortunately, commercial UNIX vendors (like HP, in my case), were very slow to adopt the standard and update the cc compiler in their distribution. This forced us to work in K&R for a good time after 1990, all the while grumbling that $150 MS-DOS compilers already 'had ANSI'.

Re: Dennis Ritchie's first C compiler on Github

#72
post #53

Earlier quoted context omitted.

I'm fairly certain that shadowing a keyword with a macro is forbidden by the standard (or invokes UB?) but this will still work for most compilers, provided LET is defined reasonably. Hm, something like #define LET(name, X) \ for (int let_once_=1, name=(X); \ let_once_; \ let_once_=0) may be reasonable, though tokenpasting in __LINE__ for good measure might be necessary for nesting.

Shadowing keywords is perfectly valid, although I believe you can't shadow keywords in standard headers so that compiler writers don't need to worry about it. It gives rise to some "useful" C/C++ features that should never be used, like if you want to access private members in foo.cpp, do #define private public #include "foo.cpp" #undef private

I can imagine some insidious menace adding this to the top of a file:

    #define public protected

Re: Dennis Ritchie's first C compiler on Github

#73
post #65
post #48

Earlier quoted context omitted.

tabs are an infinite source of pain and inconsistencies... Everyone must support the space character, it cannot be banned. But a simple commit hook to ban tabs can make indentation and alignment not get messed up over time with many collaborators with default-configured editors (that mess up and use tabs for alignment).

The inventor of the tab character is on my list of people to assassinate when they're young if I ever get access to a time machine, the other people on the list being Hitler and Charles Douglass. The tab character is a nice idea, but they do not seem to have worked out at all. I'd much rather have syntax-aware indenting in the editor, now that available compiler technology and CPU power make it practical.

I don't understand what's so bad about tabs. With tabs, all you have to do is adjust the settings in your editor, and each programmer gets the indentation (s)he wants: 2, 4, 8, whatever...

Also, do you really want to be pressing the space bar twelve times, instead of tabbing three times?

I've seen the results of spaces-only: inconsistent, sloppy indentation, 7 or 9 spaces instead of 8, as long as it looks "indented" enough.

How, specifically does the tab character "not seem to have worked out at all"?

I'm not saying you're wrong for using spaces, just wondering...

Re: Dennis Ritchie's first C compiler on Github

#74
post #68
post #65

Earlier quoted context omitted.

The inventor of the tab character is on my list of people to assassinate when they're young if I ever get access to a time machine, the other people on the list being Hitler and Charles Douglass. The tab character is a nice idea, but they do not seem to have worked out at all. I'd much rather have syntax-aware indenting in the editor, now that available compiler technology and CPU power make it practical.

I am just thinking, why not solve this at the scm level, e.g. make a git plugin that will check out the sources indentation independent and only show changes to contents of the file not the indentation. You could even make a plugin that works without collaboration by others: check out the file in your preferred style and transform the changes back into the original style.

I totally agree. I seem to recall an experimental clang-based git plugin for this floating around. I think it even handled certain differences in naming convention.

We'll probably get there in a few more years, as we get comfortable with adding more power to these systems, and taking advantage of compiler technology for things other than generating code.

Re: Dennis Ritchie's first C compiler on Github

#75
post #66

The declaration of printf is both scary and pretty cool. What happens when you have more then 9 substitutions specified in the string? :D edit: decided the code was a bit long to have pasted into my post. Can find it at the bottom of http://cm.bell-labs.com/cm/cs/who/dmr/last1120c/c03.c

This is the compiler's printf(), not the one that gets linked in with compiled code. As long as the compiler itself doesn't have more than 9 substitutions, it's OK. Your code will link with a different one.

Re: Dennis Ritchie's first C compiler on Github

#76
post #65

Earlier quoted context omitted.

The inventor of the tab character is on my list of people to assassinate when they're young if I ever get access to a time machine, the other people on the list being Hitler and Charles Douglass. The tab character is a nice idea, but they do not seem to have worked out at all. I'd much rather have syntax-aware indenting in the editor, now that available compiler technology and CPU power make it practical.

I don't understand what's so bad about tabs. With tabs, all you have to do is adjust the settings in your editor, and each programmer gets the indentation (s)he wants: 2, 4, 8, whatever... Also, do you really want to be pressing the space bar twelve times, instead of tabbing three times? I've seen the results of spaces-only: inconsistent, sloppy indentation, 7 or 9 spaces instead of 8, as long as it looks "indented"…

Don't confuse the tab character with the tab key.

The key is great. I use it all the time. Of course I don't want to press the space bar twelve times instead of tabbing three times. Of course I don't want sloppy indentation with 7 or 9 spaces instead of 8. Is this an actual problem? I've literally never seen either one in ~25 years of using languages that need indentation. The editor takes care of it.

The problem with the tab character is that there's no standard for how wide they're supposed to be, and so everyone uses them differently. Sure, in theory you use one tab character to indicate one level of indentation, and everybody can be happy. In practice, they're often not used that way. People will use two-space tabs with four-space indentation, using two tab characters to indent. People will use eight-space tabs with four-space indentation, using four spaces for one level of indentation, a tab character for two levels, a tab character followed by four spaces for three levels, etc. Some people just blithely mix and match for no particular reason. Put either one into an editor with different tab settings and it explodes into a huge mess.

Re: Dennis Ritchie's first C compiler on Github

#77
post #67

I'm ashamed for having to google his name but for others like me here's a glimpse: "Dennis MacAlistair Ritchie (born September 9, 1941; found dead October 12, 2011) was an American computer scientist who "helped shape the digital era." He created the C programming language and, with long-time colleague Ken Thompson, the Unix operating system" http://en.wikipedia.org/wiki/Dennis_Ritchie

You should have seen HN when he died. It was that hell week of a bunch of early computer pioneers all passed away...

To be honest, I don't remember much of a hullaballo when either Dennis Ritchie or John McCarthy died. There was a post or two on each event, but nothing like when Steve Jobs died (when literally the entire front page was posts about his death).

(All three events were in October 2011 - Jobs, then Ritchie, then McCarthy)

Re: Dennis Ritchie's first C compiler on Github

#78
post #22
post #9

Earlier quoted context omitted.

I understand bootstrapping, but at some point there has to exist some outside compiler in another language or a hand-compiled version of this otherwise the chicken and egg chain never ends.

The very first compilers were tediously written in assembly. Bill Gates wrote his first version of Basic in assembly. I believe all early Fortran compilers were written in direct machine code through punch cards! Coding in assembly is not all that bad :). Once you got some compiler going, you can write more complex compiler with it and keep adding more syntactic sugar :).

Coding in Assembly was a gas! I wrote applications in IBM BAL in the 70's. G/L, Payroll, Inventory. We did it in part because we had so little memory (typically 64K to 131K), we had to squeeze every drop we could out of available memory.

I worked on Univac 9400s. We received the O/S in source code form (Assembly) on tape. We ran it through a parametizer (PROC), compiled the resulting source, and that's what the customer ran with.

You haven't lived until you've stepped through your code one instruction at a time, displaying op codes and raw binary data on the maintenance panel lights.

Re: Dennis Ritchie's first C compiler on Github

#79

Earlier quoted context omitted.

if(foo) I avoid doing this because it looks like a function call.

In an appropriately powerful language, it could be a function call.

Which is exactly why you don't do it in a language where it isn't.

Re: Dennis Ritchie's first C compiler on Github

#80
post #76

Earlier quoted context omitted.

I don't understand what's so bad about tabs. With tabs, all you have to do is adjust the settings in your editor, and each programmer gets the indentation (s)he wants: 2, 4, 8, whatever... Also, do you really want to be pressing the space bar twelve times, instead of tabbing three times? I've seen the results of spaces-only: inconsistent, sloppy indentation, 7 or 9 spaces instead of 8, as long as it looks "indented"…

Don't confuse the tab character with the tab key . The key is great. I use it all the time. Of course I don't want to press the space bar twelve times instead of tabbing three times. Of course I don't want sloppy indentation with 7 or 9 spaces instead of 8. Is this an actual problem? I've literally never seen either one in ~25 years of using languages that need indentation. The editor takes care of it. The problem wi…

Just use tabs for indentation and spaces for alignment.
Post reply on HN