Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   macro preprocessing C51 x armcc (http://www.velocityreviews.com/forums/t893966-macro-preprocessing-c51-x-armcc.html)

entik 03-23-2012 09:11 AM

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

Code:

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;
END_CLASS

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

Code:

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

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 ;)

Thanks
Entik

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.