lwip-devel
[Top][All Lists]
Advanced

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

RE: [lwip-devel] Initializing static/global variables


From: Goldschmidt Simon
Subject: RE: [lwip-devel] Initializing static/global variables
Date: Tue, 26 Jun 2007 17:22:16 +0200

Do we really want to be that variable? I'd be OK with memsetting to zero, but initializing e.g. the tcp_backoff table or broadcast addresses with such a define leads to pretty strange code (to me, at least).

I'd vote for either static _or_ dynamic initialization.

Simon.

-----Originalnachricht-----
Von: address@hidden
An: address@hidden
Gesendet: 26.06.2007 16:25
Betreff: [lwip-devel] Initializing static/global variables

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;
 ....
}




_______________________________________________
lwip-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-devel


reply via email to

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