[En-Nut-Discussion] Nut/OS Initialization

Alain M. alainm at pobox.com
Wed Sep 17 18:44:16 CEST 2008


To both Thiado and Nathan,

Using NutMain() is not against C rules, using something before main() 
is. In C++ constructors before main() is not against rules but is 
condidered by many people (including Bruce Eckel, Thinging in C++) as a 
bad programing style.

The reason is not only phylosophical, it makes simple debugging become 
possible nightmares. As you apen a nut system in Eclipse it goes 
straight to main() and you cannot debug anything before that. I had to 
do it with Nut, and it took me 2 days to find a simple error in one 
initialization ... :(

Alain

Nathan Moore escreveu:
> On Wed, Sep 17, 2008 at 11:09 AM, Alain M. <alainm at pobox.com> wrote:
> 
>> Thiago A. Corrêa escreveu:
>>> I don't know exactly how this is implemented in the C code, but we
>>> could use this approach to remove the hardware init from main.
>>> If some void hardwareInit() is provided, then it will be called before
>> main (?)
>>
>> That is against C rules. So I vote against it :(
> 
> 
> How is this against C rules?  Lots of stuff typically happens before main is
> called in programs.
> Under linux _init is the standard entry point for a program, and it loads
> ld.so which is responsible
> for loading any other libraries that the program needs before main is ever
> called.  There is also a
> test for static and/or global class constructor calls (even if the app isn't
> C++, objective C, or other
> OO language) that happens before main is called.
> This isn't unlike the preparation that main() would need to come up.
> Also, nut/os's main already does break the rules since it doesn't get argc
> and argv and main can't
> return in Nut/Os.
> Having an user definable hardware init that gets called before threads are
> enabled seems like a good
> thing to me.  In other embedded OSes it's common for the first code that
> runs to be code that wasn't
> written by the OS vendor, but since Nut/Os is ~vended~ by the producer of
> the boards that it is
> intended to run on the current init is done by code that is in the OS
> distribution.
> 
> Nathan
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
> 
> 



More information about the En-Nut-Discussion mailing list