Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#42 The defines CU_ASSERT_* contain brace

open
Anil Kumar
Core Issue (23)
5
2012-10-25
2010-03-10
regseb
No

Hello,

There is a problem when I use CU_ASSERT_*() in a if without brace :
if (i == j)
CU_ASSERT_EQUAL (i, 0);
else
CU_ASSERT_EQUAL (i, 1);

With gcc, I have the error : ‘else’ without a previous ‘if’. Because CU_ASSERT_EQUAL() is replaced by { CU_assertImplementation(); }, so the code makes :
if (i == j)
{ CU_assertImplementation(); };
else
{ CU_assertImplementation(
); };

The define contains one instruction, so you can replace { CU_assertImplementation(); } by CU_assertImplementation().
For example :

define CU_ASSERT(value) \

{ CU_assertImplementation((value), LINE, #value, FILE, "", CU_FALSE); }
Will become :

define CU_ASSERT(value) \

CU_assertImplementation((value), LINE, #value, FILE, "", CU_FALSE)

Discussion

  • define CU_ASSERT(value) \

    do { CU_assertImplementation((value), LINE, #value, FILE, "", CU_FALSE); } while(0)

     


Anonymous


Cancel   Add attachments