Skip to content

Commit 3f08d52

Browse files
committed
Fix MSVC 2017 warnings
/W4
1 parent f881105 commit 3f08d52

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

benchmark.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef double (*function1)(double);
3838
static void bench(const char *expr, function1 func) {
3939
int i, j;
4040
volatile double d;
41-
double tmp;
41+
static double tmp;
4242
clock_t start;
4343

4444
te_variable lk = {"a", {&tmp}, TE_VARIABLE, NULL};

example2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main(int argc, char *argv[])
1414

1515
/* This shows an example where the variables
1616
* x and y are bound at eval-time. */
17-
double x, y;
17+
static double x, y;
1818
te_variable vars[] = {{"x", {&x}, TE_VARIABLE, NULL}, {"y", {&y}, TE_VARIABLE, NULL}};
1919

2020
/* This will compile the expression and check for errors. */

test.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static void test_infs() {
277277

278278
static void test_variables() {
279279

280-
double x, y, test;
280+
static double x, y, test;
281281
te_variable lookup[] =
282282
{{"x", {&x}, TE_VARIABLE, NULL},
283283
{"y", {&y}, TE_VARIABLE, NULL},
@@ -356,7 +356,7 @@ static void test_variables() {
356356

357357
static void test_functions() {
358358

359-
double x, y;
359+
static double x, y;
360360
te_variable lookup[] =
361361
{{"x", {&x}, TE_VARIABLE, NULL}, {"y", {&y}, TE_VARIABLE, NULL}};
362362

@@ -390,7 +390,7 @@ static void test_functions() {
390390
}
391391

392392

393-
static double sum0() {
393+
static double sum0(void) {
394394
return 6;
395395
}
396396
static double sum1(double a) {
@@ -418,7 +418,7 @@ static double sum7(double a, double b, double c, double d, double e, double f, d
418418

419419
static void test_dynamic() {
420420

421-
double x, f;
421+
static double x, f;
422422
te_variable lookup[] = {
423423
{"x", {&x}, TE_VARIABLE, NULL},
424424
{"f", {&f}, TE_VARIABLE, NULL},
@@ -494,8 +494,8 @@ static double cell(void *context, double a) {
494494

495495
static void test_closure() {
496496

497-
double extra;
498-
double c[] = {5,6,7,8,9};
497+
static double extra;
498+
static double c[] = {5,6,7,8,9};
499499

500500
te_variable lookup[] = {
501501
{"c0", {.cl0=clo0}, TE_CLOSURE0, &extra},
@@ -602,7 +602,7 @@ static void test_pow() {
602602
};
603603
#endif
604604

605-
double a = 2, b = 3;
605+
static double a = 2, b = 3;
606606

607607
te_variable lookup[] = {
608608
{"a", {&a}, TE_VARIABLE, NULL},

tinyexpr.c

+29-8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ For log = natural log uncomment the next line. */
4040
#include <string.h>
4141
#include <stdio.h>
4242
#include <limits.h>
43+
#include <assert.h>
4344

4445
#ifndef NAN
4546
#define NAN (0.0/0.0)
@@ -95,6 +96,26 @@ static te_expr *new_expr(const int type, const te_expr *parameters[]) {
9596
return ret;
9697
}
9798

99+
static te_expr *new_expr1(const int type, te_expr *p1) {
100+
const size_t size = sizeof(te_expr) + (IS_CLOSURE(type) ? sizeof(void*) : 0);
101+
assert(p1 && ARITY(type) == 1);
102+
te_expr *ret = malloc(size);
103+
ret->type = type;
104+
ret->v.bound = 0;
105+
ret->parameters[0] = p1;
106+
return ret;
107+
}
108+
109+
static te_expr *new_expr2(const int type, te_expr *p1, te_expr *p2) {
110+
const size_t size = sizeof(te_expr) + sizeof(void*) + (IS_CLOSURE(type) ? sizeof(void*) : 0);
111+
assert(p1 && p2 && ARITY(type) == 2);
112+
te_expr *ret = malloc(size);
113+
ret->type = type;
114+
ret->v.bound = 0;
115+
ret->parameters[0] = p1;
116+
ret->parameters[1] = p2;
117+
return ret;
118+
}
98119

99120
static void te_free_parameters(te_expr *n) {
100121
if (!n) return;
@@ -405,7 +426,7 @@ static te_expr *power(state *s) {
405426
if (sign == 1) {
406427
ret = base(s);
407428
} else {
408-
ret = NEW_EXPR(TE_FUNCTION1 | TE_FLAG_PURE, base(s));
429+
ret = new_expr1(TE_FUNCTION1 | TE_FLAG_PURE, base(s));
409430
ret->v.f.f1 = negate;
410431
}
411432

@@ -433,19 +454,19 @@ static te_expr *factor(state *s) {
433454

434455
if (insertion) {
435456
/* Make exponentiation go right-to-left. */
436-
te_expr *insert = NEW_EXPR(TE_FUNCTION2 | TE_FLAG_PURE, insertion->parameters[1], power(s));
457+
te_expr *insert = new_expr2(TE_FUNCTION2 | TE_FLAG_PURE, insertion->parameters[1], power(s));
437458
insert->v.f.f2 = t;
438459
insertion->parameters[1] = insert;
439460
insertion = insert;
440461
} else {
441-
ret = NEW_EXPR(TE_FUNCTION2 | TE_FLAG_PURE, ret, power(s));
462+
ret = new_expr2(TE_FUNCTION2 | TE_FLAG_PURE, ret, power(s));
442463
ret->v.f.f2 = t;
443464
insertion = ret;
444465
}
445466
}
446467

447468
if (neg) {
448-
ret = NEW_EXPR(TE_FUNCTION1 | TE_FLAG_PURE, ret);
469+
ret = new_expr1(TE_FUNCTION1 | TE_FLAG_PURE, ret);
449470
ret->v.f.f1 = negate;
450471
}
451472

@@ -459,7 +480,7 @@ static te_expr *factor(state *s) {
459480
while (s->type == TOK_INFIX && (s->v.f.f2 == pow)) {
460481
te_fun2 t = s->v.f.f2;
461482
next_token(s);
462-
ret = NEW_EXPR(TE_FUNCTION2 | TE_FLAG_PURE, ret, power(s));
483+
ret = new_expr2(TE_FUNCTION2 | TE_FLAG_PURE, ret, power(s));
463484
ret->v.f.f2 = t;
464485
}
465486

@@ -476,7 +497,7 @@ static te_expr *term(state *s) {
476497
while (s->type == TOK_INFIX && (s->v.f.f2 == mul || s->v.f.f2 == divide || s->v.f.f2 == fmod)) {
477498
te_fun2 t = s->v.f.f2;
478499
next_token(s);
479-
ret = NEW_EXPR(TE_FUNCTION2 | TE_FLAG_PURE, ret, factor(s));
500+
ret = new_expr2(TE_FUNCTION2 | TE_FLAG_PURE, ret, factor(s));
480501
ret->v.f.f2 = t;
481502
}
482503

@@ -491,7 +512,7 @@ static te_expr *expr(state *s) {
491512
while (s->type == TOK_INFIX && (s->v.f.f2 == add || s->v.f.f2 == sub)) {
492513
te_fun2 t = s->v.f.f2;
493514
next_token(s);
494-
ret = NEW_EXPR(TE_FUNCTION2 | TE_FLAG_PURE, ret, term(s));
515+
ret = new_expr2(TE_FUNCTION2 | TE_FLAG_PURE, ret, term(s));
495516
ret->v.f.f2 = t;
496517
}
497518

@@ -505,7 +526,7 @@ static te_expr *list(state *s) {
505526

506527
while (s->type == TOK_SEP) {
507528
next_token(s);
508-
ret = NEW_EXPR(TE_FUNCTION2 | TE_FLAG_PURE, ret, expr(s));
529+
ret = new_expr2(TE_FUNCTION2 | TE_FLAG_PURE, ret, expr(s));
509530
ret->v.f.f2 = comma;
510531
}
511532

0 commit comments

Comments
 (0)