1

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.

serenity
  • 11
  • 5
  • 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. – serenity May 31 '13 at 17:05
  • 1
    Even though you are answering your own question, it is still customary to put it as an answer and accept the answer. Otherwise it will always show as an unanswered question and future developers may not find the solutions they need. – Tevo D Jun 06 '13 at 12:53
  • Hi Tevo, sorry for taking this too long, I just re-login after all this time. I just followed your suggestion to put my finding as an answer. – serenity Aug 09 '16 at 17:44

1 Answers1

0

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! :)

serenity
  • 11
  • 5