Royce Pereira wrote:

On Mon, 01 Oct 2007 13:02:32 +0530, David Brown
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?

If the function is globally visible (i.e., not static to the file), then
the compiler must generate a working function - "ret" is as small and
fast as it gets.

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.

The compiler will inline calls to the function in the same translation
unit, and thus eliminate the "ret".

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

There is no way in C to express the idea of a time delay - the
language has no concept of time. Thus you have to go out of your
way to tell the compiler to be particularly stupid if you want this
sort of code to work.  There are other ways to get a delay, such as
the library routines or hardware timers, or by including something
like an "asm volatile ("nop")" in the loop, but using a volatile
loop counter is an easy way to get an approximate delay loop.

Of course, there's no disputing that. But the delay loop is just an
example, of how simple ,intuitive code can throw the compiler into a
tizzy. I've used SDCC(for mcs51) where the compiler 'recognises' code
patterns, and says "Oh, I know what this is - it's a delay loop! -
Let it pass."(for example).

That sounds to me like a very bad idea, as you'll find out the day you write a slightly unusual delay loop which is not pattern matched, and your code gets eliminated.

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

I prefer software to do as I tell it, but perhaps to warn me if that's not what it thinks I mean. Thus gcc will accept code like "if (a = 1) ...", but will warn that it's probably not what I meant. Of course, it would all be a lot easier if the language in question had a way to express what I want!

Regards, --Royce.

AVR-GCC-list mailing list

Reply via email to