syntaxmacrospicmplab-c18

C macro syntax error (C18 compiler)


I got a syntax error when trying to compile this macro. I have to use a macro as C18 doesn't support function inlining. Using a regular function call will cause the compiler to have a much bigger ISR overhead (normally it's about 10 assembly instructions, with a function call it became 50).

I checked, there are no trailing spaces.

#define INCREMENT_IDX(puIdx,uMax)  uMax--;\
                                   if (*puIdx <= uMax)\
                                   {\
                                       (*puIdx)++;\
                                       if (*puIdx > uMax)\
                                       {\
                                           *puIdx = 0;\
                                       }\
                                   }\
                                   else\
                                   {\
                                       return(FALSE);\
                                   }\
                                   return(TRUE);

And the compiler raised a syntax error when I call the macro:

unsigned char uIndex;

INCREMENT_IDX(&uIndex, MAX_QUEUE_SIZE)

Thank you.


Never mind, I found the answer. The problem is I am using another macro as the "input parameter" when "calling" the macro. Since it's a macro, it's just a replace, so no internal/temporary variable is created.

So, I fixed it by doing this:

unsigned char uIndex, uMax = MAX_QUEUE_SIZE;
INCREMENT_IDX(&uIndex, uMax)

Thank you all! :)

P.S.: I tried to answer this queston to close it, but I couldn't do it before 8 hours of posting. So, I just put the answer here.


Solution

  • Never mind, I found the answer. The problem is I am using another macro as the "input parameter" when "calling" the macro. Since it's a macro, it's just a replace, so no internal/temporary variable is created.

    So, I fixed it by doing this:

    unsigned char uIndex, uMax = MAX_QUEUE_SIZE;
    INCREMENT_IDX(&uIndex, uMax)
    

    Thank you all! :)