[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Problem with delay loop

From: Dave Hansen
Subject: RE: [avr-gcc-list] Problem with delay loop
Date: Tue, 2 Oct 2007 16:16:44 -0400

> From: address@hidden
> Hi,
> On Mon, 01 Oct 2007 13:02:32 +0530, David Brown <address@hidden> wrote:
> > Royce Pereira wrote:
> >>
> >> So I have to write more 'C' code :) to get the same stuff done, in
> >> the 'new & smarter' compiler! Interesting.....
> >>
> >> Doesn't seem right, some how.
> >>
> >> Regards, --Royce.
> >
> > It might not seem right, but that's the way it is. The compiler only
> > has to generate code that has the same effect as the source you've
> > written, and a simple "ret" has that effect.
> Why then was the empty 'ret' function retained?
> I would think such a case would be the prime candidate for optimisation.
> The compiler should eliminate such a funtion, as well as all calls to that function.
> That would really make a difference in size/speed of the code.

I don't remember the code.  Was the function declared static?  If not, the compiler must generate at least the ret since functions external to the file could potentially call it as well.  If the function was static, the code for it (and the calls to it) could indeed be removed entirely.

Years ago, I ran a simple test on a compiler for the 80386.  The code

   static int square(int n)
      return n*n;

   int test(void)
      return square(3);


      mov ax,9

So in that case, no code was generated for the static function.

> (Instead, the compiler destroys a perfectly good delay loop I've used for the last 2 years -yes, I'm still sore)

Sorry, I must disagree.  It was not "perfectly good."  As the fact that the compiler was able to legally destroy it demonstrates.


> I've always maintained - good software is one that does what you *want* it to do, *not* what you tell it to do. ;)

Sorry, I must again disagree.  All too often, software that attempts to DWIM (Do What I Mean) guesses wrong, and I have to clean up a mess.  E.g., try entering acronyms in Microsoft Word, and watch it "correct" them for you.



Windows Live Hotmail and Microsoft Office Outlook – together at last. Get it now!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]