diff options
-rw-r--r-- | cgen.c | 5 | ||||
-rw-r--r-- | test.toc | 3 | ||||
-rw-r--r-- | types.c | 6 |
3 files changed, 11 insertions, 3 deletions
@@ -1326,6 +1326,11 @@ static void cgen_expr(CGenerator *g, Expression *e) { cgen_write(g, "%.16Lf", (long double)e->floatl); break; case EXPR_LITERAL_INT: + /* make sure it's the right type (for variadic foreign functions) */ + cgen_write(g, "("); + cgen_type_pre(g, &e->type); + cgen_type_post(g, &e->type); + cgen_write(g, ")"); cgen_write(g, U64_FMT, e->intl); break; case EXPR_LITERAL_STR: { @@ -2,7 +2,8 @@ printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int; main ::= fn() { - printf("hey\n\0"); + x := "hey %ld %ld %ld %ld %ld\n\0"; + printf(&x[0], 5, 3, 8, 9, 4); }; main();
\ No newline at end of file @@ -2103,8 +2103,10 @@ static Status types_expr(Typer *tr, Expression *e) { } else { if (nargs != nparams) { - err_print(e->where, "Expected %lu arguments to function call, but got %lu.", (unsigned long)nparams, (unsigned long)nargs); - return false; + if (!has_varargs || nargs < nparams-1) { + err_print(e->where, "Expected %lu arguments to function call, but got %lu.", (unsigned long)nparams, (unsigned long)nargs); + return false; + } } for (size_t p = 0; p < nargs; ++p) { if (args[p].name) { |