mirror of https://github.com/rui314/chibicc.git
Add va_copy()
This commit is contained in:
parent
b6d3cd00df
commit
603de502fd
|
@ -49,6 +49,8 @@ static void *__va_arg_fp(__va_elem *ap, int sz, int align) {
|
||||||
__va_arg_mem(ap, sizeof(ty), _Alignof(ty))); \
|
__va_arg_mem(ap, sizeof(ty), _Alignof(ty))); \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#define va_copy(dest, src) ((dest)[0] = (src)[0])
|
||||||
|
|
||||||
#define __GNUC_VA_LIST 1
|
#define __GNUC_VA_LIST 1
|
||||||
typedef va_list __gnuc_va_list;
|
typedef va_list __gnuc_va_list;
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,4 @@ int strcmp(char *p, char *q);
|
||||||
int strncmp(char *p, char *q, long n);
|
int strncmp(char *p, char *q, long n);
|
||||||
int memcmp(char *p, char *q, long n);
|
int memcmp(char *p, char *q, long n);
|
||||||
void exit(int n);
|
void exit(int n);
|
||||||
|
int vsprintf();
|
||||||
|
|
|
@ -28,12 +28,14 @@ int sum2(int x, ...) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *fmt(char *buf, char *fmt, ...) {
|
void fmt(char *buf, char *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vsprintf(buf, fmt, ap);
|
|
||||||
va_end(ap);
|
va_list ap2;
|
||||||
return buf;
|
va_copy(ap2, ap);
|
||||||
|
vsprintf(buf, fmt, ap2);
|
||||||
|
va_end(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -42,6 +44,7 @@ int main() {
|
||||||
ASSERT(21, sum2(1, 2.0, 3, 4.0, 5, 6.0, 0));
|
ASSERT(21, sum2(1, 2.0, 3, 4.0, 5, 6.0, 0));
|
||||||
ASSERT(21, sum2(1, 2.0, 3, 4.0, 5, 6.0, 0));
|
ASSERT(21, sum2(1, 2.0, 3, 4.0, 5, 6.0, 0));
|
||||||
ASSERT(210, sum2(1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9, 10.0, 11, 12.0, 13, 14.0, 15, 16.0, 17, 18.0, 19, 20.0, 0));
|
ASSERT(210, sum2(1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9, 10.0, 11, 12.0, 13, 14.0, 15, 16.0, 17, 18.0, 19, 20.0, 0));
|
||||||
|
ASSERT(0, ({ char buf[100]; fmt(buf, "%d %d", 2, 3); strcmp(buf, "2 3"); }));
|
||||||
|
|
||||||
printf("OK\n");
|
printf("OK\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue