diff --git a/tests/cast.c b/tests/cast.c index 0459a4413..395be7b86 100644 --- a/tests/cast.c +++ b/tests/cast.c @@ -27,7 +27,7 @@ void test_castbool() int main() { - plan(7); + plan(11); START_TEST(cast) START_TEST(castbool) @@ -41,5 +41,14 @@ int main() char *c = (char *) 0; is_true(c == NULL); + double *d2 = 0; + is_true(d2 == NULL); + int *i2 = 0; + is_true(i2 == NULL); + float *f2 = 0; + is_true(f2 == NULL); + char *c2 = 0; + is_true(c2 == NULL); + done_testing(); } diff --git a/transpiler/transpiler.go b/transpiler/transpiler.go index 52d49c43f..777b2ae20 100644 --- a/transpiler/transpiler.go +++ b/transpiler/transpiler.go @@ -152,6 +152,11 @@ func transpileToExpr(node ast.Node, p *program.Program, exprIsStmt bool) ( expr, exprType, preStmts, postStmts, err = transpileMemberExpr(n, p) case *ast.ImplicitCastExpr: + if n.Kind == "NullToPointer" { + expr = util.NewIdent("nil") + exprType = types.NullPointer + return + } if strings.Contains(n.Type, "enum") { if d, ok := n.Children()[0].(*ast.DeclRefExpr); ok { expr, exprType, err = util.NewIdent(d.Name), n.Type, nil