Reputation: 40175
I have the following code
#if defined(TESTING)
#define TEST_FAILED_IN_VMC(...) TestFailed(__FILE__, __LINE__, __VA_ARGS__)
#define TEST_FAILED_IN_UNIT_TEST(...) TestFailedInUnitTest(__VA_ARGS__)
#else
#define TEST_FAILED_IN_VMC(...)
#define TEST_FAILED_IN_UNIT_TEST(...)
#endif
and make a call TEST_FAILED_IN_VMC(peripheral, testSuiteName, testName,
"Internal coding error; bad state (%d)", state);
and the compiler complians that testSuiteName
and testName
are not defined - even though #TESTING
is not defined.
[Update] The compiler also says "Error 3 implicit declaration of function 'TEST_FAILED_IN_VMC'
[Update] Please ignore veryting below this line. The problem is above. Thanks.
So, I tried this [Update] else
should be #else
, then I am told that TESTING
is not defiend. SO, why is the code above not working?
#if defined(TESTING)
#error "Testing is defined <<<<<<<<<<<<<<<<<<<<<<<<"
wf
else
#error "Testing is NOT defined <<<<<<<<<<<<<<<<<<"
eyh6
#endif
#ifdef TESTING
#error "Testing is defined @@"
ehye
else
#error "Testing is NOT defined @@"
5he567
#endif
#error "Sample error ###"
and the only error the compiler gave was Error 3 #error "Sample error ###"
Any idea what is going wrong? (Atmel AVR Studio, which is based on Microsoft Visual studio`.
Many, many, many other #if defined
are working just fine ...
Upvotes: 1
Views: 891
Reputation: 5154
You're missing the #
before the else
s.
EDIT: For the real question you added, I've tried the following code which does compile and run without any problem in gcc 4.5.2.
#include <stdio.h>
#if defined(TESTING)
#define TEST_FAILED_IN_VMC(...) TestFailed(__FILE__, __LINE__, __VA_ARGS__)
#define TEST_FAILED_IN_UNIT_TEST(...) TestFailedInUnitTest(__VA_ARGS__)
#else
#define TEST_FAILED_IN_VMC(...)
#define TEST_FAILED_IN_UNIT_TEST(...)
#endif
int main()
{
TEST_FAILED_IN_VMC
(
peripheral
, testSuiteName
, testName
, "Internal coding error; bad state (%d)"
, state
);
printf("Test successful\n");
return 0;
}
So, what compiler (and what version) are you using?
Upvotes: 2
Reputation: 25740
Instead of else
, use #else
to use the correct preprocessor directive.
Upvotes: 3