You probably think I'm totally crazy and terribly bad at programming. One of them may be, but please read my conclusions.
Yes I #include <math.h>
Full code can be found here. (I tried to make it ansi compatible in order to compile it on VS2010, through a mixed code and declaration error, as well as fminf (). I was surprised that VS2010 cared for mixed code and declaration with default warning levels. I remember that 2008 did not care, but may be wrong.)
Here is an example of gcc using the c89 / -ansi standard. pay attention to implicit function declarations. There are several others about unused parameters, but at the moment we don’t care. (required for signing to register callbacks using GLUT)
When I run the application using the c89 or ansi standard, it gives the wrong output, just like math functions do not behave as expected.
$ STANDARD=-std=c89 make -f Makefile.Unix
gcc -std=c89 -Wextra -Wall -pedantic -c -o file-util.o file-util.c -I/usr/X11R6/include
gcc -std=c89 -Wextra -Wall -pedantic -c -o gl-util.o gl-util.c -I/usr/X11R6/include
gcc -std=c89 -Wextra -Wall -pedantic -c -o meshes.o meshes.c -I/usr/X11R6/include
In file included from meshes.c:12:
vec-util.h: In function ‘vec_length’:
vec-util.h:10: warning: implicit declaration of function ‘sqrtf’
meshes.c: In function ‘calculate_flag_vertex’:
meshes.c:48: warning: implicit declaration of function ‘sinf’
meshes.c:50: warning: implicit declaration of function ‘cosf’
gcc -std=c89 -Wextra -Wall -pedantic -c -o flag.o flag.c -I/usr/X11R6/include
In file included from flag.c:18:
vec-util.h: In function ‘vec_length’:
vec-util.h:10: warning: implicit declaration of function ‘sqrtf’
flag.c: In function ‘update_p_matrix’:
flag.c:58: warning: implicit declaration of function ‘fminf’
flag.c: In function ‘mouse’:
flag.c:252: warning: unused parameter ‘x’
flag.c:252: warning: unused parameter ‘y’
flag.c: In function ‘keyboard’:
flag.c:261: warning: unused parameter ‘x’
flag.c:261: warning: unused parameter ‘y’
flag.c: At top level:
vec-util.h:1: warning: ‘vec_cross’ defined but not used
vec-util.h:13: warning: ‘vec_normalize’ defined but not used
gcc -o flag file-util.o gl-util.o meshes.o flag.o -L/usr/X11R6/lib -lGL -lglut -lGLEW
Now, using the c99 standard, the implicit declaration of function messages has disappeared.
$ STANDARD=-std=c99 make -f Makefile.Unix
gcc -std=c99 -Wextra -Wall -pedantic -c -o file-util.o file-util.c -I/usr/X11R6/include
gcc -std=c99 -Wextra -Wall -pedantic -c -o gl-util.o gl-util.c -I/usr/X11R6/include
gcc -std=c99 -Wextra -Wall -pedantic -c -o meshes.o meshes.c -I/usr/X11R6/include
gcc -std=c99 -Wextra -Wall -pedantic -c -o flag.o flag.c -I/usr/X11R6/include
flag.c: In function ‘mouse’:
flag.c:252: warning: unused parameter ‘x’
flag.c:252: warning: unused parameter ‘y’
flag.c: In function ‘keyboard’:
flag.c:261: warning: unused parameter ‘x’
flag.c:261: warning: unused parameter ‘y’
flag.c: At top level:
vec-util.h:1: warning: ‘vec_cross’ defined but not used
vec-util.h:13: warning: ‘vec_normalize’ defined but not used
gcc -o flag file-util.o gl-util.o meshes.o flag.o -L/usr/X11R6/lib -lGL -lglut -lGLEW
When using the c99 standard, the program behaves as desired and expected.
Question
Why does using the -ansi flag seem to remove ads from math.h?
source
share