comp.lang.ada
 help / color / mirror / Atom feed
* Ada vs. C
@ 1996-08-07  0:00 The Quelisher
  1996-08-09  0:00 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: The Quelisher @ 1996-08-07  0:00 UTC (permalink / raw)



I have found one thing that C has an advantage over Ada : executable
file sizes. Everything I have programmed in Ada is HUGE compared to a
program thta does the same thing but written in C.

Just my $.02
-- 
    *.........................................*
    .                |/                       .
    .                |\ENDAL                  .
    . WWW   => http://www.cs.fsu.edu/~vandyke .
    . EMail => kendal@freenet.scri.fsu.edu    .
    . Pager => (904) 297-6658                 .
    .                                         .
    *.........................................*




^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: "Subtract C, add Ada"
@ 1995-01-20  4:43 Samuel Mize
  1995-01-21 20:28 ` David O'Brien
  0 siblings, 1 reply; 16+ messages in thread
From: Samuel Mize @ 1995-01-20  4:43 UTC (permalink / raw)


In article <3f5s92$3id@info.epfl.ch>,
Laurent Gasser <gasser@masg1.epfl.ch> wrote:
>
>The problem is in the language definition, not in the choic of symbols.
>C is one of the rare language I use to allow having an assignment after 
>the if statement.  All other languages only allow for a boolean test.
>
>I never saw a good reason for allowing this.
>

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).

Consider the common C idiom to copy a null-terminated
array, usually a string [syntax may not be quite right]:

     while (*a++=*b++);

Recall that C considers 0 false, a null character is integer
0, and an assignment returns what was assigned.  This loop
condition copies the character at address b to address a,
increments both, and exits when a null was copied.  There is
no statement inside the loop.

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.

* ++ can use the assembler's increment instruction.  a=a+1
  could not.

* 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.

Thus, with a lot of man-hours, expertise and skull-sweat,
someone using a basic C compiler can come within an order
of magnitude of the efficiency of someone using a half-good
optimizing Ada compiler.  Often.

Of course, if you only *read* the code, and don't *run*
it, it looks like the C is more optimized, because you can
*see* the optimizations.

With Ada you write less-optimized-looking code, and trust
the compiler.  (But verify.)

>-- 
>Laurent Gasser (gasser@dma.epfl.ch)
>Computers do not solve problems, they execute solutions.
>
>I know very few ideas worth dying for, none is worth killing.

I dunno, I've killed quite a few ideas in my time :-)

Sam Mize - smize@starbase.neosoft.com




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~1996-08-16  0:00 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-07  0:00 Ada vs. C The Quelisher
1996-08-09  0:00 ` Robert Dewar
1996-08-09  0:00   ` The Quelisher
1996-08-10  0:00     ` Robert Dewar
1996-08-10  0:00     ` steved
1996-08-10  0:00       ` Robert Dewar
1996-08-10  0:00     ` Bob Kitzberger
1996-08-11  0:00     ` Dave Wood
1996-08-14  0:00       ` busigin
1996-08-16  0:00         ` Robert Dewar
1996-08-11  0:00     ` Jerry van Dijk
1996-08-12  0:00   ` Vladimir Vukicevic
1996-08-09  0:00 ` Jack W Scheible
1996-08-09  0:00 ` Daniel P Hudson
1996-08-09  0:00   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1995-01-20  4:43 "Subtract C, add Ada" Samuel Mize
1995-01-21 20:28 ` David O'Brien
     [not found]   ` <3g655n$q5k@theopolis.orl.mmc.com>
1995-01-30 15:33     ` Ada vs. C Martijn Bak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox