manning@nntp-server.caltech.edu (Evan Marshall Manning) (09/21/90)
I'm having some trouble getting the symbols in #defined constants into
strings. It seems like what I'm doing below should work (__MSDOS__
side of #ifdef) but it gives:
The table has 2 values:
8 8
GO 0
instead of:
The table has 2 values:
MAX_AE 8
GO 0
Near as I can tell from July '90 CUJ everyone's scrambling for fancy
ways to put the value in strings & putting the symbol is what happens
when you're not careful. But it doesn't work for me.
Thanks
-- Evan
**********************************************************************
#include <stdio.h>
#ifdef __MSDOS__
#define STRINGIZE(arg) #arg
#else
#define STRINGIZE(arg) "arg"
#endif
#define MAX_AE 8
typedef enum
{
GO,
NOGO
} gonogo;
#define TBL_CONST(symbol) { STRINGIZE(symbol), symbol}
typedef struct {
char sv_symb[21];
int sv_value;
} symbol_value_type;
symbol_value_type syval[]
= {
TBL_CONST(MAX_AE),
TBL_CONST(GO)
};
#define NUM_TBL_CONST (sizeof(syval) / sizeof(syval[0]))
main (void) {
int syval_ix;
printf("The table has %d values:\n", NUM_TBL_CONST);
for ( syval_ix = 0; syval_ix < NUM_TBL_CONST; syval_ix++ ) {
printf("%20s\t%5d\n", syval[syval_ix].sv_symb,
syval[syval_ix].sv_value);
}
}
***************************************************************************
Your eyes are weary from staring at the CRT for so | Evan M. Manning
long. You feel sleepy. Notice how restful it is | is
to watch the cursor blink. Close your eyes. The |manning@gap.cco.caltech.edu
opinions stated above are yours. You cannot | manning@mars.jpl.nasa.gov
imagine why you ever felt otherwise. | gleeper@tybalt.caltech.edu