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.

3
  • 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. Commented May 31, 2013 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. Commented Jun 6, 2013 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. Commented Aug 9, 2016 at 17:44

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.