[Top][All Lists]

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

Re: [avr-gcc-list] Newbie - should this work?

From: Joerg Wunsch
Subject: Re: [avr-gcc-list] Newbie - should this work?
Date: Tue, 21 Jan 2003 17:41:09 +0100 (MET)

Tom Harris <address@hidden> wrote:

> The docs for -ffreestanding do not seem to mention any effect on
> main(),

Then you must have a different man page than I:

       Compile for a freestanding  environment;  this  im-
       plies  the  `-fno-builtin' option, and implies that
       main has no special requirements.

In a hosted environment, the only prototypes for main() that are
allowable are

int main(void);
int main(int, char **);

(and compatible, namely char ** can be expressed in another way, too).

In a freestanding environment, main() is no longer special, so any
prototype for it is allowable.

I have writte a few lines about the effect of -ffreestanding in the
avr-libc docs.  You might want to read it, there are more side effects
than you mention (which influence optimization).

> I always have main() returning void (in an embedded system, where
> would main() return to?), ...

There is not much point in this method (i. e., i'd consider it a cruel
hack to "fix" it by supressing a warning), and it will fail to work in
a C++ environment where the compiler insists on a correctly declared
main().  If you write something like:

        for (;;) {
                /* program main loop */

        return 0;

you are fully compliant with the C standard, and the optimizer will
eliminate the trailing "return 0;" anyway because it is unreachable.

All serious MCU programs will certainly have their own main loop, so
this should never become a real problem.
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/
avr-gcc-list at http://avr1.org

reply via email to

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