Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site kobold.UUCP Path: utzoo!linus!security!genrad!grkermit!masscomp!kobold!tjt From: tjt@kobold.UUCP (T.J.Teixeira) Newsgroups: net.lang Subject: Re: Untyped languages? (BCPL) Message-ID: <224@kobold.UUCP> Date: Thu, 29-Dec-83 10:27:14 EST Article-I.D.: kobold.224 Posted: Thu Dec 29 10:27:14 1983 Date-Received: Sat, 31-Dec-83 11:48:49 EST References: <489@tekchips.UUCP> <2465@azure.UUCP> Organization: Masscomp, Westford, MA Lines: 75 BCPL explicitly assumes that memory is word addressed, and all values (integers, pointers, floating point numbers) can be represented in a word. This works out fine for machines addressed this way. e.g. PDP-10's, GE-645 (now Honeywell 6180's -- i.e. Multics), older minicomputers (if you ignore floating point). BCPL is not good for character strings. Strings are stored in a dense representation, but there is no good way to reference individual characters from BCPL, aside from shifting and masking. Then again, that's unavoidable on a word-addressed machine. If memory is byte addressed rather than word addressed, BCPL is less attractive. The compiler is either painfully constructing byte addresses, or you drop the requirement that adding 1 to an address gets you the address of the next "word". The first is inefficient for the operations lv and rv (like unary & and * in C), but a toss-up for real array accesses (to evaluate E1[E2] in C you would normally scale E2 by the size of the object pointed to by E1 (or vice versa -- as has been pointed out E1[E2] is equivalent to E2[E1]) -- in BCPL you would just add E1 to E2 and scale the sum). The second approach causes most existing BCPL programs to break. In addition, on a byte-addressed machine the lack of an operator to perform byte addressing seems more annoying and inefficient. I never used B, but my Sixth Edition C Reference Manual states: C is a computer language based on the earlier language B. The languages and their compilers differ in two major ways: C introduces the notion of types, and defines appropriate extra syntax and semantics; also, C on the PDP-11 is a true compiler, producing machine code where B produced interpreted code. I suspect that one of the original reasons for introducing data types was because those data values required different amount of storage. In order to do address scaling automatically, it is necessary to keep track of the types of pointers. Once you have any types, you might as well implement float and double rather than introduce special floating point operators (e.g. $+, $-, $* and $/ were floating point operations in BCPL). For a long time, type checking in C was very weak. Numeric types (char, int, float and double) were widened or narrowed inside an expression, but pointer types were not checked (i.e. for structure references). The types of function arguments are still not checked by the compiler. Curiously enough, BCPL and C are complementary languages in the sense that machines that are good for BCPL are not good for C, and vice versa. BCPL is difficult to implement on a byte-addressed machine, and character arrays in C are hard to implement on word-addressed machine. I suspect that if byte-addressed minicomputers hadn't come around (i.e. if Ken Thompson and Dennis Ritchie had stayed with the PDP-7/9/15 line), UNIX would have been written in BCPL. P.S. BCPL stands for Basic *Combined* Programming Language, not *Computer* language and is related to CPL (Combined Programming Language). I don't know anything about CPL (the references I have for it are to a 1963 issue of The Computer Journal), but the abstract for one version of BCPL Reference Manual (from BBN) states: BCPL is a a simple recursive programming language designed for compiler writing and system programming; it was derived from true CPL (Combined Programming Language) by removing those features of the full language which make compilation difficult, namely, the type and mode matching rules and the variety of definition structures with their associated scope rules. Whaddya mean, difficult to implement? It's only taken ten years, and we almost have most of it working. Seriously, does anyone out there know how close modern C is to CPL? -- Tom Teixeira, Massachusetts Computer Corporation. Westford MA ...!{ihnp4,harpo,decvax,ucbcad,tektronix}!masscomp!tjt (617) 692-6200