demula
demula

Reputation: 1364

Preprocessor not skipping asm directives

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

Upvotes: 1

Views: 280

Answers (2)

nategoose
nategoose

Reputation: 12382

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.

Upvotes: 0

JayM
JayM

Reputation: 4898

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.

Upvotes: 1

Related Questions