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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,dab7d920e4340f12 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,dab7d920e4340f12 X-Google-Attributes: gid103376,public From: clodius@hotspec.lanl.gov (William Clodius) Subject: Re: C is 'better' than Ada because... Date: 1996/07/29 Message-ID: #1/1 X-Deja-AN: 170906542 sender: clodius@hotspec.lanl.gov references: <31e02c32.342948604@netline-fddi.jpl.nasa.gov> organization: Los Alamos National Laboratory newsgroups: comp.lang.ada,comp.lang.c Date: 1996-07-29T00:00:00+00:00 List-Id: In article <01bb7bfc$3c5ca460$96ee6fcf@timhome2> "Tim Behrendsen" writes: Ken Garlington wrote in article <31EF7E48.5ABE@lmtas.lmco.com>... > Sandy McPherson wrote: > > and produce efficient machine code. > > Why is this an advantage of C over Ada? Ada certainly produces efficient > machine code, given a good compiler. In fact, there are examples of Ada > outperforming C with regard to efficiency. The one big advantage C has traditionally had over other languages is efficient compilation. The reason is that 'C' is one of the few languages that provides concepts such as register variables to give hints to the compiler. This ignores Garlington's reply. If this was important, why do languages such as Ada, Fortran, Sisal, etc., often generate more efficient code than C athough they lack that hint? On heavily pipelined processors, register scheduling is such a complex task that the human analysis is rarely useful and that hint is almost uniformly ignored. As to compiler speed, while C's coding brevity helps some aspects of compilation, its typical reliance on macros and the details of its declaration syntax result in a language that is harder to compile than some other languages such as Oberon. Yes, you can wave your hand and say, "well, the compiler should take care of that". But then, reality rears its head, and we realize that there are *no* compilers that are that smart. Here's an old saying that I just made up ... Behrendsen's Law: "All optimizers are crap." We will never have an optimizer that can do as good a job as human optimization until we get "strong AI", but that would take an actual science of AI to exist (let's not get started on *that*!). C is one of few languages that recognizes this. While on modern processors a human can still compete with a compiler on small pieces of code, provided he works directly in assembler, doing that on every portion of a significant code is too exhausting for humans. C is no substitute for assembler in such cases. The aspects of C that are thought of as resembling assembler, either loose semantic information usefull for global analysis, e.g., the distinction between pointers and arrays, or are shorthands for constructs, e.g., i=i+1, that are easily recognized by any compiler. Since C is such a small language, this also makes it easier for the compiler/optimizer to a (relatively) good job. Most compilers nowadays use backends that are common among several languages, and most optimizations are performed in the language independent backends. The size of the language has relatively little effect on optimization compared to the detailed semantics of the language. Strong typing in any language helps with optimization, and both C and Ada (indeed many other languages) have strong typing. Unfortunately, while C is a small language, its reliance on pointers and side effects introduces optimization problems not present in many other languages, e.g, Ada, Fortran, Sisal, etc. -- William B. Clodius Phone: (505)-665-9370 Los Alamos National Laboratory Email: wclodius@lanl.gov Los Alamos, NM 87545