28 Jul 2012, 04:50
When I compile
unity_fixture.c with gcc 4.4.3 and
-O0, it compiles cleanly. However, when I compile it with
-O1 or greater, I get the following warning:
gcc -IUnity/src -IUnity/extras/fixture/src -O1 -c Unity/extras/fixture/src/unity_fixture.c -o test/build/unity_fixture.o
Unity/extras/fixture/src/unity_fixture.c: In function ‘unity_malloc’:
Unity/extras/fixture/src/unity_fixture.c:202: warning: incompatible implicit declaration of built-in function ‘malloc'
<stdlib.h> before any reference to
malloc, so I can’t see why this would be happening, let alone only happening at some optimization levels.
It’s causing trouble for me because I’d like to use
-Werror on my builds.
21 Dec 2012, 20:37
I’ve tracked this bug down. The short answer is,
unity_fixture.c should include
string.h before unity_fixture.h.
It seems that
string.h on Linux may include a minimal
stdlib.h which includes definitions for malloc and calloc (see
bits/string2.h and the macro
unity_fixture.h is included in
string.h, a preprocessor definition of
unity_malloc exists when
stdlib.h accidentally emits a prototype for a function named
unity_malloc instead of one named malloc.
stdlib.h also sets
__malloc_and_calloc_defined so that it doesn’t try to define those functions twice, so the later explicit including of
stdlib.h doesn’t get us the
calloc prototypes we want.
09 Jan 2013, 17:47
You must be logged in to comment