Re: #defines and strings
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Thu, 30 Jun 2005 15:11:19 +0000 (UTC)
In article <1120136034.488821.20890@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
GMM50 <george.martin@xxxxxxx> wrote:
>In the code I use these messages as constants as:
> PlayMsg(SM1023, OutputChannel, Volume);
>So I'm planning to use a define to convert SM1023 to the internal
>storage number (= location).
>#define SM1023 19 // Hello Message
>But then when the user downloads a message I need to programatically
>determine it's internal storage number (= location).
>struct MSG_CVRG MsgTbl[] = {
> 1023, 19; // Hello Message
> 0, 0;
>}
>My problem is I now have data in two places and they will get out of
>sync.
Perhaps I'm missing something, but why not use
struct MSG_CVRG MsgTbl[] = {
1023, SM1023, // Hello Message
0, 0,
};
(Note: semicolons converted to commas)
Potentially you might also want to consider
#define PASTE(T1,T1) T1##T2
#define DclMsg(N) {N, PASTE(SM,N)}
struct MSG_CVRG MsgTbl[] = {
DclMsg(1023),
DclMsg(1196),
DclMsg(1197),
{0, 0},
};
Also, you might not need the trailing {0, 0} as you can take
sizeof(MsgTabl) / sizeof(struct MSG_CVRG)
to find out how many elements there are.
--
The rule of thumb for speed is:
1. If it doesn't work then speed doesn't matter. -- Christian Bau
.
- References:
- #defines and strings
- From: GMM50
- #defines and strings
- Prev by Date: Re: "basic" pointer question
- Next by Date: Re: why use -> (not .) with pointers?
- Previous by thread: #defines and strings
- Next by thread: Re: #defines and strings
- Index(es):
Relevant Pages
|