Pregunta

I'm using Visual Studio 2005 and getting trained in building WinCE 6.0 OS Image. I'm in the pin mux setup part. I have set a macro BSP_HC1, so the coding with that macro alone should work. A part of the coding is,

#define GPMC_PADS \
#ifdef BSP_HC1
    PAD_ENTRY(GPMC_A6   ,INPUT_DISABLED | MUXMODE(SAFE_MODE))   \
    PAD_ENTRY(GPMC_nCS2 ,INPUT_DISABLED | MUXMODE(0))   
#else
    PAD_ENTRY(GPMC_A1       ,INPUT_DISABLED | MUXMODE(0))     \
    PAD_ENTRY(GPMC_A2       ,INPUT_DISABLED | MUXMODE(0))     \
    PAD_ENTRY(GPMC_A3       ,INPUT_DISABLED | MUXMODE(0))
#endif

The IntelliSense was correctly showing the else part as an inactive code. But, while I select Build, I was getting error as "error: C2449 found '{' at file scope (missing function header?)".

So, I added backslashes at the end of #ifdef, #else and #endif.

#define GPMC_PADS \
#ifdef BSP_HC1  \
    PAD_ENTRY(GPMC_A6   ,INPUT_DISABLED | MUXMODE(SAFE_MODE))   \
    PAD_ENTRY(GPMC_nCS2 ,INPUT_DISABLED | MUXMODE(0))   \
#else   \
    PAD_ENTRY(GPMC_A1       ,INPUT_DISABLED | MUXMODE(0))     \
    PAD_ENTRY(GPMC_A2       ,INPUT_DISABLED | MUXMODE(0))     \
    PAD_ENTRY(GPMC_A3       ,INPUT_DISABLED | MUXMODE(0))     \
#endif

There were no errors while building. But, I wonder whether I have done the right thing and my coding will do the intended purpose, because I have done it blindly. I thought that the #ifdef and other related pre-processor directives need not be included in the macro definition GPMC_PADS and the compiler would treat it separately. Kindly explain me, if I'm wrong.

¿Fue útil?

Solución

You can not use pre-processor directives within #defines.

Do it this way:

#ifdef BSP_HC1
#define GPMC_PADS \
  PAD_ENTRY(GPMC_A6   ,INPUT_DISABLED | MUXMODE(SAFE_MODE))   \
  PAD_ENTRY(GPMC_nCS2 ,INPUT_DISABLED | MUXMODE(0))   
#else
#define GPMC_PADS \
  PAD_ENTRY(GPMC_A1       ,INPUT_DISABLED | MUXMODE(0))     \
  PAD_ENTRY(GPMC_A2       ,INPUT_DISABLED | MUXMODE(0))     \
  PAD_ENTRY(GPMC_A3       ,INPUT_DISABLED | MUXMODE(0))
#endif
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top