Common pre-C89 compiler/stdlib idioms (1985-1988)
Asked Answered
G

5

7

I'm writing a C compiler for the fictional DCPU-16 CPU (which will be used in the 0x10C game). In this game world any original software written for the system has been developed before (or during) 1988: so I'm trying to write my compiler like it was coded between 1985-1988. I've got a copy of the C89 standard, but would like to know how common compilers preceding this differed from the standard and the common coding styles of the period.

So far this is what I'm assuming:

  • I need to use preprocessor support to define both old and new style function definitions/prototypes.
  • Coding style generally uses "something_with_an_underscore" for types, functions and variables (is this true? how prevelant was Hungarian notation during the period? what about camel case?)

Other things I would like to know:

  • How did common c compilers/stdlibs differ from the later C89 standard?
  • What common code patterns were in vogue?
  • How were common variables named at the time (i, n, foo, bar?)
  • Do you have any example code from the time?
  • Etc...
Greenman answered 30/1, 2013 at 19:12 Comment(7)
The original C reference manual should help. It also contains some sample code that captures the flavor of the time.Upstanding
I hear it was common and/or sometimes necessary to put all local variable declarations at the beginning of a function, though C89 allowed them at the beginning of any block.Puebla
Isn't the "original C reference manual" from the 1970s - which makes it at least 10 years away from C89 - I'm interested in the messy history between the two.Greenman
@JimBalter: The "original C reference manual" linked above does not allow declarations in a compound-statement, only at the beginning of a function body.Puebla
@JimBalter but (C99, 6.8.2p2) "A compound statement is a block."Fowl
So I think aschepler (and commenter’s et all) has given me another "rule": Declare all variables at the beginning of the function (to allow for the compiler not supporting block-local variable definitions).Greenman
Compilers of the time period you are interested in supported block-local variable definitions. As for whether people wrote such code during that period ... it depends on the people. This is true in general of code patterns and variable names. Most C programmers continue to write code the way they always have, which is the way they were taught or the sort of code they saw when they started.Yul
L
2

When there's no defined standard, people only care about getting it "work". It's applicable to just about anything, not just C language. So it's hard tell the difference between all pre-standard coding styles/naming conventions etc against the standadized one. I'd think most would have just followed whatever there in K&R books (1st & 2nd).

For samples...

You can look at Dennis Ritchie's site where he has given some examples: Very early C compilers and language. You can search through that site for more relevant information. But I don't think you'd get answers for all your questions.

Leenaleeper answered 30/1, 2013 at 19:30 Comment(12)
The second edition of K&R is based on the 1989 ANSI C standard. K&R1 was published in 1978. Earlier C references are available on the web.Thresher
The one I have (K&R2) says 1988 and its code samples doesn't follow C89 standard :)Leenaleeper
The upcoming ANSI standard was nearly finished in 1988. What code samples violate the C89 standard?Thresher
For example, all main() have just main() {..} and main() doesn't return anything.Leenaleeper
@KingsIndian which is valid in C89.Fowl
The "implicit int" rule wasn't dropped until C99. Failing to return a value from main() wasn't illegal, it just returned an undefined status to the environment. (C99 made reaching the closing } of main() equivalent to return 0;.)Thresher
@KeithThompson ..returned an undefined status to the environment which I thought is non-standard. Thanks for the info.Leenaleeper
@KeithThompson There is 11 years between K&R1 and ANSI-C. The major compilers over those years helped define ANSI-C: and I'm interested in the (mostly unwritten) history of how they differed from the standard they helped define (and to a lesser extent how they differed from the older standard they evolved from). If you have any links to good compiler specific references (especially post 1985) then please post them.Greenman
@0x0D0A: The discussion in these comments is mostly about K&R2, not K&R1 -- and K&R2 isn't particularly helpful for what you're asking about. I don't have any compiler-specific references beyond what's on Dennis Ritchie's web page, which KingsIndian already linked to.Thresher
@KeithThompson Yeah it's an obscure question (I was hoping people who were actually coding at the time could provide some background). I looked up the history/evolution of C on wikipedia before posting this and it's almost non-existent (which considering the languages current ubiquity is kind-of sad). I guess I'll have to pay for the numerous draft specifications (assuming they still exist) and try and scrounge some old compliers (from Woz/God knows where). Maybe when I'm done I'll have a go at writing the history of C article on Wikipedia myself...Greenman
@0x0D0A: The second HOPL conference in 1993 included a paper on the history of C. I don't know whether it includes information that's not on DMR's web page.Thresher
@Greenman draft specifications are irrelevant; any prior to C89 will look very much like C89, which mostly reflected compilers of the time, plus some inventions that weren't in any compilers of the time. Your question is confused because it asks about numerous things, some of which have nothing to do with time period, like what variable names were used.Yul
E
1

One weird ugly thing you could do, which might make a neat 'puzzle' in the game, is that very early preprocessors would actually scan for and replace defined macros in the contents of string literals!

So, for instance

#define foo bar
char *s = "That would be a foolish thing to do!";

would be preprocessed to

char *s = "That would be a barlish thing to do!";
Extradition answered 12/8, 2014 at 22:2 Comment(0)
G
1

The ANSI X3J11 committee that was responsible for standardizing the C language was formed in 1983, and in April 1985 they published a first draft. According to Eric S. Raymond, "[the C language] has been essentially stable since copies of the X3J11 committee's working papers on the Draft Proposed Standard signaled the committee's intentions to compiler implementers in 1985-1986". [1]

Studying a compiler manual from the '85-'86 timeframe, such as Lattice C [2] or Microsoft C 4.0 [3], shows that these compilers had already begun to support most of ANSI C89. The most glaring omissions are the lack of const and volatile support (although Microsoft C had already added these to the list of reserved keywords) and the continued use of "K&R"-style function definitions.

So by 1988, it wouldn't be unreasonable to see ANSI C89 code in the wild, even though the standard itself had not yet been published -- simply because the compiler writers had already been incorporating parts of the standard into their compilers for several years.

[1] http://www.catb.org/~esr/writings/taoup/html/c_evolution.html

[2] https://archive.org/details/Lattice_C_AmigaDOS_Compiler_Version_3_Programmers_Reference_Guide_1986-09-12_Lattice_Inc.

[3] http://www.os2museum.com/wp/dos/dos-library/

Grazia answered 27/5, 2019 at 11:41 Comment(0)
F
0

I've got a copy of the C89 standard, but would like to know how common compilers preceding this differed from the standard and the common coding styles of the period.

History of C was largely made by compiler vendors. When standardizing ANSI C, the C89 Committee made an effort to not break existing code. I think a pre-C89 code is likely to compile with a C89 compiler.

From the C89 Rationale:

"In specifying a standard language, the Committee used several principles, the most important of which are: [...] A large body of C code exists of considerable commercial value. Every attempt has been made to ensure that the bulk of this code will be acceptable to any implementation conforming to the Standard. The Committee did not want to force most programmers to modify their C programs just to have them accepted by a conforming translator."

Fowl answered 30/1, 2013 at 19:25 Comment(4)
I get this - but I'm not trying to write code that compiles on a C89 compiler - I'm trying to write a stylised pre C89 compiler (written in stylised pre C89 code) that mimics the period (the computing equivalent of trying to mimic the style of a 1980's pulp author).Greenman
You can get interesting information by reading a pre-C89 compiler manual, for example Lattice C 1985 manual gametronik.com/site/rubriques/amiga/FAQs/…Fowl
Well: Lattice was really very decent (and standard-obedient), comparered to the (later) standard-polluting Borland and MS stuff. Lattice was the first cross-platform "portable" compiler, for that reason it was aquired by SAS leading to its sudden death, around 1994.Tiptop
I'm kind of familiar with Borland C V2 1990(ish) (because I used it to learn C in 1995). Does any one have a Borland C V1 manual (or even better the binary with the standard library) from the 1980's?Greenman
Y
0

See http://cm.bell-labs.com/who/dmr/

especially "Resurrection of two primeval C compilers from 1972-73, including source. "

Yul answered 30/1, 2013 at 20:46 Comment(2)
This is interesting as background but still misses the 15 years of evolution (especially the last 5) that I really want some first hand knowledge of.Greenman
Your question is based on the wrong assumption that code patterns and variable names are common across time periods.Yul

© 2022 - 2024 — McMap. All rights reserved.