macro preprocessing C51 x armcc

Joined
Mar 23, 2012
Messages
2
Reaction score
0
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
 
Joined
Mar 23, 2012
Messages
2
Reaction score
0
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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top