From 63cd9d074b4239474050daed0c12bd2d2d27a2e6 Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Sun, 14 Jun 2015 17:27:41 -0500 Subject: [PATCH] fix warning for cast to pointer from integer of different size, enhance conditional check of pointer to 'if' test --- expression.c | 3 ++- tests/14_if.c | 18 ++++++++++++++++++ tests/14_if.expect | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/expression.c b/expression.c index 502e987..851b544 100644 --- a/expression.c +++ b/expression.c @@ -769,8 +769,9 @@ void ExpressionPrefixOperator(struct ParseState *Parser, (void*)((char*)TopValue->Val->Pointer-Size); break; case TokenUnaryNot: + /* conditionally checking a pointer's value */ TopValue->Val->Pointer = - (void*)((char*)(!TopValue->Val->Pointer)); + (void*)((TopValue->Val->Pointer) ? NULL : (void*)1); break; default: ProgramFail(Parser, "invalid operation"); diff --git a/tests/14_if.c b/tests/14_if.c index bb56ef4..ecb7e5a 100644 --- a/tests/14_if.c +++ b/tests/14_if.c @@ -13,5 +13,23 @@ if (b) else printf("b is false\n"); +int *c = 0; +if (c) + printf("c is true\n"); +else + printf("c is false\n"); +if (!c) + printf("c is true\n"); +else + printf("c is false\n"); +c = &b; +if (c) + printf("c is true\n"); +else + printf("c is false\n"); +if (!c) + printf("c is true\n"); +else + printf("c is false\n"); void main() {} diff --git a/tests/14_if.expect b/tests/14_if.expect index c32c415..26f6d95 100644 --- a/tests/14_if.expect +++ b/tests/14_if.expect @@ -1,2 +1,6 @@ a is true b is false +c is false +c is true +c is true +c is false