stdarg causes compile error
Posted: Wed Jul 08, 2009 10:20 pm
I have written a stdarg.h file containing only the simple gcc-builtin implementation noted on the 'Printing to Screen' wiki page. The code:
When I compile this, it causes an error message in compiling any file that includes my other header, kstdio.h, which contains printf and related utilities.
The error message is
The typedefs of u32int, etc. are all in mpos.h, which I have included in kstdio.h. When I comment out the #defines and the typedef in stdarg.h it compiles this code fine (it later gives another error relevant to va_arg, etc., not being defined). Does anyone know why this would be?
Code: Select all
/* stdarg. This defines va_start, va_list, etc. */
#ifndef STDARG_H
#define STDARG_H
#define va_start(v,l) __builtin_va_start(v,l)
#define va_arg(v,l) __builtin_va_arg(v,l)
#define va_end(v) __builtin_va_end(v)
#define va_copy(d,s) __builtin_va_copy(d,s)
typedef __builtin_va_list va_list
#endif /* STDARG_H */
Code: Select all
/* Provides stdio-like routines for in-kernel use. */
#ifndef KSTDIO_H
#define KSTDIO_H
#include "stdarg.h"
#include "mpos.h"
/* As vsnprintf() in stdio.h. Prints up to n chars to buf, using fmt and args
as printf()-like arguments.
*/
u32int vsnprintf(char *buf, u32int n, char *fmt, va_list args); // Error on this line here
/* Uses vsnprintf() above to print to the screen. */
u32int printf(char *fmt, ...);
u32int sprintx(char *, u32int);
u32int sprintd(char *, u32int);
u32int atoi(char *);
#endif /* KSTDIO_H */
Code: Select all
In file included from kernel.c:15:
kstdio.h:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'u32int'