Warning messages in Unity - theolind/mahm3lib GitHub Wiki

The "original" Unity file 'unity.c' is infested with some nasty code which generates warning messages. Here are the problems, both solved and remaining:

Solved problems

Message (totally > 15 messages):

Conversion to 'XXX' from 'YYY' may change the sign of the result

Problem:

Implicit type conversion. Consider this line of code as an example:
return Unity.TestFailures;

Solution:

Just implement explicit type conversion. Consider this line of code as an example:
return (int)Unity.TestFailures;

Message (totally 4 messages):

"braces around scalar initializer [enabled by default]"
"(near initialization for 'Unity.AbortFrame[0]') [enabled by default]"

Problem:

Initialization of global variable 'Unity'.
struct _Unity Unity = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , {{{ 0 }}} };

Solution:

Corrected the code by first studying the definition of the struct, then changed code.
struct _Unity Unity = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , { 0 } };

Message (totally 5 messages):

"no previous prototype for 'UnityTestResultsFailBegin' [-Wmissing-prototypes]"

Problem:

Functions were missing prototypes.

Solution:

Since the functions scope are only within 'unity.c', I declared them as static.

Message (totally 5 messages):

"comparing floating point with == or != is unsafe [-Wfloat-equal]"

Problem:

Four of the expressions are identical.
if ((diff * 0.0f != 0.0f) || (diff > tol))

Solution:

Since the purpose of this expression
(diff * 0.0f != 0.0f)
is to check if the result of the multiplikation isn't equal to zero, lets rewrite it to:
((diff * 0.0f < 0.0f) || (diff * 0.0f > 0.0f))

Problem:

One of the expressions looks like:
if (actual == actual)

Solution:

The purpose of the expression is to verify equivalance, which also can be expressed like this:
if (!((actual < actual) || (actual > actual)))

⚠️ **GitHub.com Fallback** ⚠️