[Top][All Lists]

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

Re: [lwip-users] Initialization of global variables

From: mat henshall
Subject: Re: [lwip-users] Initialization of global variables
Date: Fri, 5 Nov 2010 12:07:12 -0700


I have hit this problem where an environment by default turns off the
initialization of globals for 'efficiency' and expects an application
to explicit zero out the globals and statics as needed. For example, I
use an ultra low powered wifi chip that has lwIP in ROM and it loads
applicaiton code from flash on 'wake up'. TIme is energy, so the less
time the chip takes to wake up and see if it really needs to do
something and the if not, fall asleep again, the better. Only if you
really want to do something might you want to then initialize the
various modules etc.

When using subsystems and third party libraries,  it is always a
little error prone and painful to collect all the various globals into
a 'init_to_zero' function. It would be more pleasant and robust to
have the optional function provided by the library.


On Fri, Nov 5, 2010 at 11:53 AM, Simon Goldschmidt <address@hidden> wrote:
> Hey Piotr,
> I hate to turn you down on that, but the variables are deliberately not being 
> initialized: when not initialized (and thus implicitly zeroed at startup), 
> they are put into the uninitialized section and no space on disk/in flash is 
> needed. However when they are initialized to NULL, they are put NGO the 
> initialized data section, which is present on disk/in flash, too.
> As to the portability: the C standard requires non initialized data to be 
> initialized to zero at startup. It is a common error in self-made ports to 
> leave out the zeroing of the uninitialized data section (.bss for gnu bcc).
> Simon
>  Piotr Piwko <address@hidden> wrote:
>> Hello,
>> I currently implement the LwIP stack under u-boot environment and I
>> have one notice regarding global variables initialization. I think
>> that every global variable which are not static should be initialized
>> by NULL or 0 value. I mean for example:
>> file tcp.c:
>> struct tcp_pcb *tcp_bound_pcbs;
>> union tcp_listen_pcbs_t tcp_listen_pcbs;
>> struct tcp_pcb *tcp_active_pcbs;
>> struct tcp_pcb *tcp_tw_pcbs;
>> file udp.c:
>> struct udp_pcb *udp_pcbs;
>> file netif.c:
>> struct netif *netif_list;
>> struct netif *netif_default;
>> If I leave they uninitialized, after compilation and link operation
>> they will contain random values which causes the system crash during
>> LwIP initialized functions. Assumption that they will be automatically
>> filled by 0 is wrong and non-portable.
>> This modification can really save a lot of time during integration :)
>> Anyway I am impressed with LwIP project. It is very useful part of
>> software. Good job guys!
>> Regards,
>> --
>> Piotr Piwko
>> http://www.embedded-engineering.pl/
>> _______________________________________________
>> lwip-users mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/lwip-users
> _______________________________________________
> lwip-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/lwip-users


Mat Henshall
Founder and CEO, Square Connect, Inc.
San Jose, CA
cell: 650.814.7585

reply via email to

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