does codewarrior support multiline macros with parameters?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

does codewarrior support multiline macros with parameters?

2,257 Views
FocusedWolf
Contributor I
Hi,

So i'm just making sure i can do multi line macros.

We're using: "CodeWarrior Development Studio for ColdFire Architectures v6.3" and targeting this: "MCF52235 ColdFire Integrated Microcontroller"

So this is just an example of the type of macro i'm planning (My actual macro will contain 68K assembly, but this example is the same style i'll be using with the "\" and parameters):

#define max(a,b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; })

Is this ok?
Labels (1)
0 Kudos
3 Replies

358 Views
FocusedWolf
Contributor I
Ok good. Anyways I have no need for that typeof stuff, that was just in an example i dug up to refresh my memory on how to write these things.

And as far as "good" coding practices go, this is one of those times when macros seem like a good idea. my plan is to use them to implement certain 68K commands like CMP.B. Basically my code is bloated with workaround type code to do various byte level operations so one macro to do all, and not have to worry how the compare was implemented would be great.

Message Edited by FocusedWolf on 2008-09-27 07:49 AM
0 Kudos

358 Views
Lundin
Senior Contributor IV
Yes. With the exception of "typeof", that code is ISO C and must work on all standard compilers. Macros like that are on the other hand considered very poor programming, but that's another story.
0 Kudos

358 Views
CrasyCat
Specialist III
Hello
 
According to ColdFire_Build_Tools_Reference.pdf, typeof operator can be used only when GCC extension is enabled for the compiler.
 
To enable GCC extension check "Enable GCC Extension in the target settings  "C/C++ Language" Panel.
 
I did try the macro you have provided with CodeWarrior for Coldfire V6.4 (I do not have a V6.3 installed any more) and it is working well.
 
CrasyCat
0 Kudos