Skip to content

Commit

Permalink
Fix #32: va_arg for generic data types
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamPearl authored and scopeInfinity committed Oct 17, 2021
1 parent e287bf1 commit 158baea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/usr/include/stdarg.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ namespace std {
#endif

typedef struct va_list {
int *base; // using int* to jmp at 4 bytes gap
void *base;
} va_list;

#define va_start(list, last) ((list).base = (((int*)&(last))+1))
#define va_start(list, last) ((list).base = ((void*)(&(last)+1)))
#define va_end(list) (list).base = NULL
#define va_arg(list, type) (*(type*)((list).base++))
#define va_arg(list, type) (*(type*)((list).base+=sizeof(type), \
(list).base-sizeof(type)))
#define va_copy(dst, src) (dst).base = (src).base

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion src/usr/lib/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static int vsnprintf(char *s, size_t n, const char *fmt, va_list args) {
s[len++]='%';
break;
case 'c':
s[len++]=va_arg(args, char);
s[len++]=(char)va_arg(args, int);
break;
case 's':
innerstr = va_arg(args, const char*);
Expand Down

0 comments on commit 158baea

Please sign in to comment.