Macro will not compile after project converted from IAR to Microchip xc8 (in MPLab)

Hi,

I have a project I need to compile in the new Microchip xc8 Compiler.
I've updated most of it as needed, but I'm having problems converting the following Macro...

#define QGET(__x, __c )            \
    __x ## r++;                    \
    if( __x ## r >= sizeof( __x )) \
    {                              \
        __x ## r = 0;              \
    }                              \
    __c = __x ##[ __x ## r ];

Open in new window


It errors on the last line:
warning: (137) strange character "[" after ##

Any ideas what the equivalent declaration in xc8 should be?

Any help would be appreciated.

Many thanks,

James
LVL 4
James AtkinSenior Principle Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
You only need ## when concatenateing two macro tokens or a token with a value to create a new token. Certain characters cannot be used as part of concatenation. I don't think you need ## here, so try without.

This explains it quite well: https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
evilrixSenior Software Engineer (Avast)Commented:
>>  I don't think you need ## here

because foo[x] is the same as foo [x], it doesn't matter if there is a space between the token and the bracket so you don't need to paste the token to the bracket.
0
James AtkinSenior Principle Software EngineerAuthor Commented:
Perfect! Thanks for the quick response :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Embedded Hardware

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.