Debugging C Preprocessor

Status
Not open for further replies.

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
I'm newish to raw C, and a newb to macros. I've got code from a library with the following macros defined, that does not work.
Code:
#define _ISR(a,b) EMIT_PRAGMA(vector=##a)\
        __interrupt void b (void)

#define ISR(x,...)    _ISR(x,isr_##x)

/*The below doesn't set the interupt handler, and throws a compiler warning = 
"concatenation with "(" in macro "_ISR" does not create a valid token"
*/
ISR(I2C_ISR_VECTOR)
{
<Interrupt handler code>
}
However, replacing it with the expected output (below) does work.
Code:
#pragma vector=I2C_ISR_VECTOR
__interrupt void I2C_ISR(void)
{
<Interrupt handler code>
}
Why does the macro not work?
Is there a way to view the preprocessor output?
How can I fix the macro?

FWIW, I'm using the TI compiler for MSP430.
 
I don't know about your specific compiler, but in general the -E flag will emit pre-processed source code:
Code:
echo "#include <stdio.h>" | gcc -E -
Which for me (vanilla GCC on a Linux) gives:
Code:
$ gcc -E test.c
a.c:10:1: error: pasting "=" and "I2C_ISR_VECTOR" does not give a valid preprocessing token
EMIT_PRAGMA(vector=I2C_ISR_VECTOR) __interrupt void isr_I2C_ISR_VECTOR (void)
{
    <Interrupt handler code>
}
 
Status
Not open for further replies.