Velocity Reviews

Velocity Reviews (
-   C Programming (
-   -   macro preprocessing C51 x armcc (

entik 03-23-2012 09:11 AM

macro preprocessing C51 x armcc
I have following code and macros:


struct tagged_class
  unsigned short tag;
  char *format;

#define BEGIN_CLASS(name, tag, fmt)                      \
  struct tagged_class name##_class = { tag, fmt };      \           
  struct name {                                        \
  struct tagged_class *klass;
#define END_CLASS };

BEGIN_CLASS(cstring, 101, "s")
        char* value;

I have been using it quite some time with C51 compiler, no problem, it is expanded by preprocessor to


struct tagged_class cstring_class = { 101, "s" };
struct cstring {       
struct tagged_class *klass;
 char* value;

which is correct and as I want it. However, I had to move to new architecture and this is what armcc produces from the very same piece of code


struct name {                                                                         
struct tagged_class *klass;

struct tagged_class cstring_class = { 101, "s" }; \
        char* value;

The line order is wrong, name is not replaced by the first macro parameter and \ is not removed. I would be very grateful for any ideas how to fix that/make it work ;)


entik 03-23-2012 09:21 AM

Ok, at the moment I saw it on the screen, I realized the error - it didn't recognized multi-line macro. From there, it was only one google away to the answer.

A: Armcc has troubles with whitespace after line wrap character '\'. When all whitespace is removed and each macro line ends immediately after '\', it is processed well.

Hope this post helps someone else in the future and therefore is not completely useless :)

All times are GMT. The time now is 10:11 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.