1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
# include <stdarg.h>
# include "bool.h"
int sumn (int x, ...)
{
int y = 0;
void *yaba;
va_list args;
va_start (args, (void *)x); /* okay (args counts as out param) */
while (x > 0)
{
x--;
y = va_arg (args, int); /* okay */
y = va_arg (args, char *); /* type error */
y = va_arg (yaba, int); /* error */
}
return y;
}
int test (int x, char *s)
{
x = sumn(); /* bad */
x = sumn(x); /* okay */
x = sumn(s); /* bad */
x = sumn(x, s); /* okay */
x = test (x, s, x); /* bad */
return x;
}
int missingargs (int x, int y) /* this is okay */
{
y = x;
return x;
}
int severalargs (char c, int y, bool b) /* first arg: int, second char *, third extra */
{
if (b) { c = 'a'; }
return y;
}
int severalargs2 (int x) /* bad */
{
return x;
}
int voidargs (char c) /* bad */
{
c = 'a';
return 3;
}
int any (...) /* ok */
{
return 3;
}
int many1 (int x, char c, float f) /* bad */
{
x;
c;
f;
return x;
}
int many2 (int x, char c, ...)
{
c;
return x;
}
int many3 (int x) /* bad */
{
return x;
}
|