[Tfug] Developer question
Bexley Hall
bexley401 at yahoo.com
Fri Jul 6 14:51:48 MST 2007
Greetings!
--- Jude Nelson <judecn at gmail.com> wrote:
> /*
> This is a slightly different approach (i.e. depends
> on calling a run-time
> method just as the program starts), but it will
> ensure that for each
> color in color_t there exists a string form:
> */
Yes, but, as with my comments to Joe (as well as my
original stipulations re: executing code), this
forces the table to be in a DATA segment. This
means there is *some* run-time cost to initializing
it (even if it only appears as a "start up cost"...
ever wonder why so many systems take SO long to start
up? :>). And, it means I have to pay for the
table's space, *twice* -- once for the nonvolatile
image (i.e. the definition and code to initialize it)
and once for the run-time/volatile image (i.e. in
RAM someplace).
I guess the "load from disk" paradigm is too heavily
ingrained, here. :-/ Imagine a device *without*
a disk and where every *byte* (not MEGAbyte) of RAM
has a co$t associated with it...
> #include <map>
> #include <string>
>
> using namespace std;
>
> enum color_t {
> // By convention, must begin with '0'
> RED = 0,
> GREEN,
> BLUE,
> };
>
> // map colors in the enum to strings
> map< int, string > colorMap;
>
> #define TO_STRING( x ) #x
> #define MAKE_COLOR( color ) ( colorMap[ color ] =
> string( TO_STRING( color )
> ) )
>
> // call this before anything else
> void init( void ) {
>
> colorMap = map< int, string >();
>
> // color definitions go here as macro code
> MAKE_COLOR( RED );
> MAKE_COLOR( GREEN );
> MAKE_COLOR( BLUE );
>
> }
>
> // main function, etc.
> int main( int argc, char** argv ) {
>
> init();
>
> /* Code goes here */
> }
____________________________________________________________________________________
Got a little couch potato?
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz
More information about the tfug
mailing list