lwip-devel
[Top][All Lists]
Advanced

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

[lwip-devel] Initializing static/global variables


From: Robert Ammerman
Subject: [lwip-devel] Initializing static/global variables
Date: Tue, 26 Jun 2007 10:25:54 -0400

Here is a paradigm that I have used to deal with the issue of dynamic initialization of global variables in embedded environments. Note that there are two reasons one might want to do this:

(1) The embedded environment does not support static initialization of globals (there are a few!). (2) Omitting support for static initialization of globals reduces the code footprint by removing the module that handles interpreting the 'initialization table', as well as the table itself.

-----------------------------------------------------------------

In a global header included by everything:

#if defined(LWIP_USE_DYNAMIC_INITIALIZATON)
 #define LWIP_STATIC_INITIAL_VALUE(x)
 #define LWIP_DYNAMIC_INITIALIZE(x) do { x } while(0)
#else
 #define LWIP_STATIC_INITIAL_VALUE(x) = x
 #define LWIP_DYNAMIC_INITIALIZE(x) do { } while (0)
#endif

-----------------------------------------------------------------

In the header file  defining the variables for 'xxx':

int  xxx_abc LWIP_STATIC_INITIAL_VALUE(23);
#define xxx_abc_DYNINIT LWIP_DYNAMIC_INITIALIZE( xxx_abc = 23 )

int xxx_def[3]          LWIP_STATIC_INITIAL_VALUE( { 1,2,3 } );
#define xxx_def_DYNINIT LWIP_DYNAMIC_INITIALIZE(  \
    { xxx_def[0]=1; xxx_def[1]=2; xxx_def[2]=3; }     \
)

int xxx_ghi[20]  LWIP_STATIC_INITIAL_VALUE(
{ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 }
);
#define xxx_ghi_DYNINIT LWIP_DYNAMIC_INITIALIZE( \
   { int _i; for (_i=0; _i<20; ++_i) { xxx_ghi[_i] = _i; } } \
)

#define xxx_DYNINIT   \
xxx_abc_DYNINIT;   \
 xxx_def_DYNINIT;  \
xxx_ghi_DYNINIT;

-----------------------------------------------------------------

In the source file for 'xxx':

void xxx_init()
{
xxx_DYNINIT;
....
}






reply via email to

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