Skip to content

Commit de0cf70

Browse files
committed
Stop initialize void* using function pointers to conform to ANSI C
1 parent e88ca22 commit de0cf70

File tree

6 files changed

+116
-98
lines changed

6 files changed

+116
-98
lines changed

benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void bench(const char *expr, function1 func) {
4141
double tmp;
4242
clock_t start;
4343

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

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

example2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main(int argc, char *argv[])
1414
/* This shows an example where the variables
1515
* x and y are bound at eval-time. */
1616
double x, y;
17-
te_variable vars[] = {{"x", &x}, {"y", &y}};
17+
te_variable vars[] = {{"x", {&x}}, {"y", {&y}}};
1818

1919
/* This will compile the expression and check for errors. */
2020
int err;

example3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ double my_sum(double a, double b) {
1212
int main(int argc, char *argv[])
1313
{
1414
te_variable vars[] = {
15-
{"mysum", my_sum, TE_FUNCTION2}
15+
{"mysum", {.f2=my_sum}, TE_FUNCTION2}
1616
};
1717

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

test.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void test_infs() {
278278
void test_variables() {
279279

280280
double x, y, test;
281-
te_variable lookup[] = {{"x", &x}, {"y", &y}, {"te_st", &test}};
281+
te_variable lookup[] = {{"x", {&x}}, {"y", {&y}}, {"te_st", {&test}}};
282282

283283
int err;
284284

@@ -354,7 +354,7 @@ void test_variables() {
354354
void test_functions() {
355355

356356
double x, y;
357-
te_variable lookup[] = {{"x", &x}, {"y", &y}};
357+
te_variable lookup[] = {{"x", {&x}}, {"y", {&y}}};
358358

359359
int err;
360360
te_expr *expr;
@@ -416,16 +416,16 @@ void test_dynamic() {
416416

417417
double x, f;
418418
te_variable lookup[] = {
419-
{"x", &x},
420-
{"f", &f},
421-
{"sum0", sum0, TE_FUNCTION0},
422-
{"sum1", sum1, TE_FUNCTION1},
423-
{"sum2", sum2, TE_FUNCTION2},
424-
{"sum3", sum3, TE_FUNCTION3},
425-
{"sum4", sum4, TE_FUNCTION4},
426-
{"sum5", sum5, TE_FUNCTION5},
427-
{"sum6", sum6, TE_FUNCTION6},
428-
{"sum7", sum7, TE_FUNCTION7},
419+
{"x", {&x}},
420+
{"f", {&f}},
421+
{"sum0", {.f0=sum0}, TE_FUNCTION0},
422+
{"sum1", {.f1=sum1}, TE_FUNCTION1},
423+
{"sum2", {.f2=sum2}, TE_FUNCTION2},
424+
{"sum3", {.f3=sum3}, TE_FUNCTION3},
425+
{"sum4", {.f4=sum4}, TE_FUNCTION4},
426+
{"sum5", {.f5=sum5}, TE_FUNCTION5},
427+
{"sum6", {.f6=sum6}, TE_FUNCTION6},
428+
{"sum7", {.f7=sum7}, TE_FUNCTION7},
429429
};
430430

431431
test_case cases[] = {
@@ -494,10 +494,10 @@ void test_closure() {
494494
double c[] = {5,6,7,8,9};
495495

496496
te_variable lookup[] = {
497-
{"c0", clo0, TE_CLOSURE0, &extra},
498-
{"c1", clo1, TE_CLOSURE1, &extra},
499-
{"c2", clo2, TE_CLOSURE2, &extra},
500-
{"cell", cell, TE_CLOSURE1, c},
497+
{"c0", {.cl0=clo0}, TE_CLOSURE0, &extra},
498+
{"c1", {.cl1=clo1}, TE_CLOSURE1, &extra},
499+
{"c2", {.cl2=clo2}, TE_CLOSURE2, &extra},
500+
{"cell", {.cl1=cell}, TE_CLOSURE1, c},
501501
};
502502

503503
test_case cases[] = {
@@ -601,8 +601,8 @@ void test_pow() {
601601
double a = 2, b = 3;
602602

603603
te_variable lookup[] = {
604-
{"a", &a},
605-
{"b", &b}
604+
{"a", {&a}},
605+
{"b", {&b}}
606606
};
607607

608608
int i;

0 commit comments

Comments
 (0)