tags:

views:

69

answers:

2

I'm programming to a microprocessor (Coldfire) and I don't have access every day to the microprocessor trainer so I want to be able to execute some of my code on the computer.

So I'm trying to skip a part of my code when executing on the computer by defining _TEST_.

It doesn't work. It tries to compile the asm code and dies whining about not knowing the registers names (they're defined alright compiling against the Coldfire, not my Intel Core Duo).

Any ideas why it's not working? or maybe an alternative way to run the code on the pc without commenting it out?.

Here's sample code from my project:


inline void ct_sistem_exit(int status)
{
#ifdef _TEST_
    exit(status);
#else
    asm volatile(
            "moveb #0,%%d1\n\t"
            "movel #0, %%d0\n\t"
            "trap #15\n\t"
            :
            :
            : "d0", "d1"
            );
#endif /* _TEST_ */
}

If it helps: using gcc3 with cygwin on Netbeans 6.8

And the way I'm defining _TEST_:



#define _TEST_
#include "mycode.c"

int main(int argc, char** argv)
{
    ct_sistem_exit(0);
}
+1  A: 

The obvious question is did you define _TEST_? You can do it on the command line with -D_TEST_.

I can compile your code when I define it.

JayM
You're right! I did not. I was compiling another file that was importing this code and though I defined _TEST_ before including it, it wasn't defined when processing the code (I don't know why...).Besides the command line option I just discovered that Netbeans lets you define before processing:Run>Set Project Configuration>Customize...>C Compiler>Preprocessor DefinitionsThanks a lot!
demula
A: 

You normally shouldn't use symbol names that start with the underscore. Those are reserved for use by the compiler and standard libraries. It is likely that there is already a TEST defined somewhere. It should be easy enough to check for, though.

You may want to try using #warning to tell you when you are building for the test machine, which will help you test that the preprocessor is doing what you expect.

nategoose
_TEST_ wasn't used by anyone although I'll keep in mind the underscores. #warning advice added! Thanks a lot for the tips
demula