A variadic function and main()
#include <stdio.h>
#include <stdarg.h>
int f(long x,...)
{ va_list ap;
int i=0;
va_start(ap,x);
while(x)
{ i++;
printf("%ld ", x);
x=va_arg(ap,long);
}
va_end(ap);
printf("\n");
return i;
}
int main()
{ return f(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,1L<<63,0);
}
On gcc, linux and x64: even though f()'s arguments are not cast to a 64bit long, gcc seems to get it right.
$ gcc t.c && ./a.out
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 -9223372036854775808
How?