small medium large xlarge

30 Nov 2011, 17:13
Anders Eriksson (2 posts)


Thank you for an excellent book, I am now reading and testing at the same time.

I am using VC++ 2008 Express for testing

the CppUTest works fine! but when I am trying the Unity I get compile errors both on my target (softune compiler for a Fujitsu mcu) and in VC++

I have found out that GCC accepts a function declaration just before a call to the declared function inside another function, see below: I have manually done the macro prepossessing that are defined in unity_fixture.h, am I missing something here?

// RUN_TEST_CASE(LedDriver, LedsOffAfterCreate); 
   void TEST_LedDriver_LedsOffAfterCreate_run(); 

// RUN_TEST_CASE(LedDriver, TurnOnLedOne); 
   void TEST_LedDriver_TurnOnLedOne_run(); // this is row 30 that the compiler reports an error for, see below 

—-—-- compile error in VC++ 2008 express --—-
code/unity/LedDriver/LedDriverTestRunner.c(30) : error C2143: syntax error : missing ’;’ before ‘type’

To get this to work in VC++ and Softune, I had to move out the 2 function declarations above the function.

Perhaps I have missed to set some compiler switches to allow these declarations or what am I doing wrong?

Kind regards Anders Eriksson

30 Nov 2011, 17:11
Anders Eriksson (2 posts)

Hello again!

Now I have come up with a fix that is working in VC++ and Softune but NOT in GCC :(

I have changed the following in unity_fixture.h:

-------- old macro -----
#define RUN_TEST_CASE(group, name) \
        DECLARE_TEST_CASE(group, name);\

//Call this from main
#define RUN_TEST_GROUP(group)\
    void TEST_##group##_GROUP_RUNNER();\
------ end of old macro ----------

----- new macro ----------------
#define RUN_TEST_CASE(group, name) \
    { DECLARE_TEST_CASE(group, name); } \

//Call this from main
#define RUN_TEST_GROUP(group)\
    { void TEST_##group##_GROUP_RUNNER(); } \
-------- end of new macro -------------

Does anyone know why there is this difference between GCC and VC++ (and this new macro works also in Softune)?

Kind regards Anders

07 Dec 2011, 14:41
James Grenning (190 posts)

That is odd. Though the VS compilers are converging on the standard. VS2010 might be more compatible.

16 Jan 2013, 18:31
James Hood (1 post)

Hi James,

Big fan!

I’m trying to port the examples supplied in the Unity distribution to use your unity_fixture from extras in Visual Studio 2010 Professional and I’m getting the same error. :/

The changes above fixed my problem as well.

Any suggestions on how to make this work across the platforms? I’d be willing to submit a pull request to Unity, but I’m not sure the best way to solve the incompatibility. To be honest I don’t think I understand the incompatibility :)

Thanks in advance for your thoughts / advice!

You must be logged in to comment