C compiler done ? va_list/arg program working :)

This commit is contained in:
pommicket 2022-02-13 14:35:34 -05:00
parent 239a1a3c27
commit 6acd24e315
2 changed files with 21 additions and 5 deletions

View file

@ -1,3 +1,19 @@
typedef unsigned long va_list;
#define va_start(list, arg) ((list) = (unsigned long)&arg)
#define va_arg(list, type) (*((type *)(list += ((sizeof(type) + 7) & 0xfffffffffffffff8))))
#define va_end(list)
int sum(int n, ...) {
va_list args;
int i;
int total = 0;
va_start(args, n);
for (i = 0; i < n; ++i) {
total += va_arg(args, int);
}
return total;
}
long factorial(long x) {
if (x == 0) {
return 1;
@ -28,6 +44,6 @@ int f() {
}
int main(int argc, char **argv) {
return fibonacci(20);
return sum(3, -100, 200, -300);
}