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