4

In my code I define some compiler constants such as the following:

#define D_CR  '\x10'    // New line
#define D_LF  '\x13'    // New paragraph
#define D_EOS '\xFF'    // End of string

(these could be chars, ints, whatever ... )

And I want to use them in two ways, one in a string literal, and secondly in switch statements.

unsigned char dialogString[] = 
    "LOREM IMSUM" D_CR
    "DOLAR SIT A MET" D_EOS;

switch (dialogString[i]) {
    case D_CR: /* ... */ break;
    case D_LF: /* ... */ break;
    case D_EOS: /* ... */ break;
    default: printf(dialogString[i]); break;
}

The problem that I'm getting is that I'm mixing types and I'm getting compiler warnings.

dialogString.c(5) parse error: token -> ''\x10'' ; column 11

Is there any way that I can get this to work for both scenarios?

9
  • 2
    good question, but I'm afraid the preprocessor limitations won't allow that. Commented Aug 26, 2016 at 15:16
  • no, not '\x13'. It's either 13 or '\xd' or '\x0d', maybe even '\n' if you're worried about character encodings. Commented Aug 26, 2016 at 15:17
  • @pmg parse error: token -> ''\x0d' ; column 11 Commented Aug 26, 2016 at 15:20
  • @Jean-FrançoisFabre does this mean i should create two compile-time constants to sort this (one char and one string)? Commented Aug 26, 2016 at 15:21
  • 1
    I'm unclear how the codepad code addresses the problem. It just seems to define the original constants, then confirm that they have been defined. No string literals involved. Commented Aug 26, 2016 at 15:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.