Re: #defines and strings



> I'm not 100% sure I understand exactly what happens when
> "the user downloads a message." The download must be tagged
> with some kind of identifier, which I'm guessing is the numeric
> value 1023 -- if that's not it, then just disregard the rest
> of this message.

I need to convert from the message being downloaded (ie SME1023) into
the internal numbering system and that message name comes in the
download port as a text string.

> Your problem (if I've understood it) is how to keep the
> #define and the translation table synchronized, that is, how
> to be sure that if either 1023 or 19 changes it changes in
> both places simultaneously.

Exactly.

> One way is to eliminate the #define, or to replace it
> with something vacuous like `#define SM1023 1023'. Functions
> like PlayMsg() could be changed so they didn't understand the
> first argument as a "storage number," but as a value to be
> looked up in MsgTbl[]. According to your description there
> will be fewer than one thousand entries in the table, so the
> lookup cost will be small (binary search will average fewer
> than nine probes).

That works for the internal playing of messages but not the donwload
event.

> Another way is to retain both, but to generate them from
> a single common source. For example, you might treat MsgTbl[]
> as The Authoritative Word, and run a little "helper" program
> to generate a .h file from the table's contents. For more
> complicated situations, the "helper" could read some other
> kind of data file and generate both the #define lines and the
> content of MsgTbl[], but that might be overkill in your case.
>
> --
> Eric.Sosman@xxxxxxx

I've come to the same conclusion. I have a .h file

#define SME1001 2003 // Good Morning Welcome message

And then a program that converts the defines into a table. So one file
contains all the facts. I'm also considering putting the conversion
code in the product as one less it item forget about.

thanks

.