From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1d321b3a6b8bcab2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-01-21 12:28:32 PST Path: nntp.gmd.de!newsserver.jvnc.net!nntpserver.pppl.gov!princeton!gw1.att.com!csn!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!pipex!uunet!gwu.edu!seas.gwu.edu!dobrien From: dobrien@seas.gwu.edu (David O'Brien) Newsgroups: comp.lang.ada Subject: Re: "Subtract C, add Ada" Date: 21 Jan 1995 20:28:32 GMT Organization: George Washington University Message-ID: <3frqpg$re5@cronkite.seas.gwu.edu> References: <3etund$hnr@miranda.gmrc.gecm.com> <3f4mbe$rud@cronkite.seas.gwu.edu> <3f5s92$3id@info.epfl.ch> <3fnf28$s3f@Starbase.NeoSoft.COM> NNTP-Posting-Host: 128.164.9.3 X-Newsreader: TIN [version 1.2 PL2] Date: 1995-01-21T20:28:32+00:00 List-Id: In article <3fnf28$s3f@Starbase.NeoSoft.COM> you wrote: : It's a question of who optimizes your code. In the 60s, : when C was developed, compilers *couldn't* optimize code, : so the programmer had to. Many apparently-bizarre C : capabilities are there to support optimization level -1 : (programmer does the optimizations). C was designed in the 70's. The earliest reference I could find to it is the cc(1) UNIX 3rd Edition man page dated 3/15/72 from "A Quarter Century of Unix". The language from which C developed, B, was created in 1970. And the only published document on the B language, "CSTR #8 - The Programming Language B", is dated Jan 1973. BCPL, which B came from, is from 1969. So, I think that "compilers *couldn't* optimize code" may be an over generalization. Is this _really_ the case for 1970's compiler technology? : Consider the common C idiom to copy a null-terminated : array, usually a string [syntax may not be quite right]: : while (*a++=*b++); I am curious about programming culture. Notice that when someone writes something in C they feel they have to remove all white space. When they write in Ada they put in plenty and use [very] long names for every thing. Why is that??? No wonder people say C is hard to read. : This is more efficient, with a non-optimizing compiler, than : while (*a) : { *a = *b; a=a+1; b=b+1}; /*or whatever is right syntax*/ : because : * The operator ++ increments the value of while it's still : in a register. The second code reads a from memory to : do the character assign, reads it again to increment it. You are making a *major* assumption about the CPU this is running on. On many smaller uP's there isn't that many registers. : * ++ can use the assembler's increment instruction. a=a+1 : could not. Since adding 1 to variable is so common place, it is trivial to add this type of optimization (even in your parser). : * Using the assignment as the loop expression indirectly : directs the compiler to keep the result of the assignment : in a register for reuse in the expression, instead : of writing it to memory, then reading it. Again, you really are thinking with a preconceived notion of your hardware. -- David O'Brien (dobrien@sea.gwu.edu)