Skip to content

Commit 937f660

Browse files
committed
Fix gcc warnings
-Wall -Wextra -Wshadow -Wcast-align -Wmissing-declarations -Wmissing-prototypes -Wconversion -Wno-long-long -pedantic
1 parent de0cf70 commit 937f660

File tree

5 files changed

+71
-63
lines changed

5 files changed

+71
-63
lines changed

benchmark.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535

3636
typedef double (*function1)(double);
3737

38-
void bench(const char *expr, function1 func) {
38+
static void bench(const char *expr, function1 func) {
3939
int i, j;
4040
volatile double d;
4141
double tmp;
4242
clock_t start;
4343

44-
te_variable lk = {"a", {&tmp}};
44+
te_variable lk = {"a", {&tmp}, TE_VARIABLE, NULL};
4545

4646
printf("Expression: %s\n", expr);
4747

@@ -53,12 +53,12 @@ void bench(const char *expr, function1 func) {
5353
tmp = i;
5454
d += func(tmp);
5555
}
56-
const int nelapsed = (clock() - start) * 1000 / CLOCKS_PER_SEC;
56+
const long int nelapsed = (clock() - start) * 1000 / CLOCKS_PER_SEC;
5757

5858
/*Million floats per second input.*/
5959
printf(" %.5g", d);
6060
if (nelapsed)
61-
printf("\t%5dms\t%5dmfps\n", nelapsed, loops * loops / nelapsed / 1000);
61+
printf("\t%5ldms\t%5ldmfps\n", nelapsed, loops * loops / nelapsed / 1000);
6262
else
6363
printf("\tinf\n");
6464

@@ -74,47 +74,47 @@ void bench(const char *expr, function1 func) {
7474
tmp = i;
7575
d += te_eval(n);
7676
}
77-
const int eelapsed = (clock() - start) * 1000 / CLOCKS_PER_SEC;
77+
const long int eelapsed = (clock() - start) * 1000 / CLOCKS_PER_SEC;
7878
te_free(n);
7979

8080
/*Million floats per second input.*/
8181
printf(" %.5g", d);
8282
if (eelapsed)
83-
printf("\t%5dms\t%5dmfps\n", eelapsed, loops * loops / eelapsed / 1000);
83+
printf("\t%5ldms\t%5ldmfps\n", eelapsed, loops * loops / eelapsed / 1000);
8484
else
8585
printf("\tinf\n");
8686

8787

88-
printf("%.2f%% longer\n", (((double)eelapsed / nelapsed) - 1.0) * 100.0);
88+
printf("%.2f%% longer\n", (((double)eelapsed / (double)nelapsed) - 1.0) * 100.0);
8989

9090

9191
printf("\n");
9292
}
9393

9494

95-
double a5(double a) {
95+
static double a5(double a) {
9696
return a+5;
9797
}
9898

99-
double a52(double a) {
99+
static double a52(double a) {
100100
return (a+5)*2;
101101
}
102102

103-
double a10(double a) {
103+
static double a10(double a) {
104104
return a+(5*2);
105105
}
106106

107-
double as(double a) {
107+
static double as(double a) {
108108
return sqrt(pow(a, 1.5) + pow(a, 2.5));
109109
}
110110

111-
double al(double a) {
111+
static double al(double a) {
112112
return (1/(a+1)+2/(a+2)+3/(a+3));
113113
}
114114

115115
int main(int argc, char *argv[])
116116
{
117-
117+
(void)argc; (void)argv;
118118
bench("sqrt(a^1.5+a^2.5)", as);
119119
bench("a+5", a5);
120120
bench("a+(5*2)", a10);

example.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
int main(int argc, char *argv[])
55
{
6+
(void)argc; (void)argv;
67
const char *c = "sqrt(5^2+7^2+11^2+(8-2)^2)";
78
double r = te_interp(c, 0);
89
printf("The expression:\n\t%s\nevaluates to:\n\t%f\n", c, r);

example2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
int main(int argc, char *argv[])
55
{
6+
(void)argc; (void)argv;
67
if (argc < 2) {
78
printf("Usage: example2 \"expression\"\n");
89
return 0;
@@ -14,7 +15,7 @@ int main(int argc, char *argv[])
1415
/* This shows an example where the variables
1516
* x and y are bound at eval-time. */
1617
double x, y;
17-
te_variable vars[] = {{"x", {&x}}, {"y", {&y}}};
18+
te_variable vars[] = {{"x", {&x}, TE_VARIABLE, NULL}, {"y", {&y}, TE_VARIABLE, NULL}};
1819

1920
/* This will compile the expression and check for errors. */
2021
int err;

example3.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33

44

55
/* An example of calling a C function. */
6-
double my_sum(double a, double b) {
6+
static double my_sum(double a, double b) {
77
printf("Called C function with %f and %f.\n", a, b);
88
return a + b;
99
}
1010

1111

1212
int main(int argc, char *argv[])
1313
{
14+
(void)argc; (void)argv;
1415
te_variable vars[] = {
15-
{"mysum", {.f2=my_sum}, TE_FUNCTION2}
16+
{"mysum", {.f2=my_sum}, TE_FUNCTION2, NULL}
1617
};
1718

1819
const char *expression = "mysum(5, 6)";

0 commit comments

Comments
 (0)