statham@cactus.org (Perry L. Statham) (04/25/91)
/* Can anyone tell me why this program does not compile and how to fix it. Operating System: SCO Xenix 2.3.3 Dev Kit Release 2.3.0d Compiler Message: testprog.c(19) : error 65: 'va_alist' : undefined Line 19 is the line that has va_start on it. The release lines for the two header files are: * @(#) stdio.h 1.10 88/10/26 * @(#) varargs.h 1.1 88/10/26 Any help is appreciated. Perry Statham perry@statham.cactus.org (512) 335-3881 (Home) (512) 467-1396 (Work) */ #include <stdio.h> #include <varargs.h> void sceprintf( char *, ... ); main() { sceprintf("0x%x %d\n",1,1); } void sceprintf( format, ... ) char *format; { FILE *log; va_list argptr; if ((log = fopen("logfile","a+")) != NULL) { va_start(argptr); vfprintf(log,format,argptr); va_end(argptr); fclose(log); } }
aryeh@eddie.mit.edu (Aryeh M. Weiss) (04/25/91)
In article <6596@cactus.org> statham@cactus.org (Perry L. Statham) writes: > >/* >Can anyone tell me why this program does not compile and how to fix it. > >Compiler Message: > testprog.c(19) : error 65: 'va_alist' : undefined > ... >void sceprintf( format, ... ) >char *format; >{ > FILE *log; > va_list argptr; > > if ((log = fopen("logfile","a+")) != NULL) { > va_start(argptr); > vfprintf(log,format,argptr); > va_end(argptr); > fclose(log); > } >} There are two implementations of ``varargs'' in Xenix. The header <varargs.h> is for K&R coding styles while <stdarg.h> is for ANSI coding style. The va_start is defined differently in the two styles. Since you are using an almost ANSI coding style you could try the following: #include <stdarg.h> void sceprintf(char *format, ... ) { FILE *log; va_list argptr; if ((log = fopen("logfile","a+")) != NULL) { va_start(argptr,format); /* Makes argptr point to 1st argument AFTER format */ vfprintf(log,format,argptr); va_end(argptr); fclose(log); } } For K&R coding style use: #include <varargs.h> void sceprintf(format, va_alist) char *format; va_dcl /* NO semicolon! */ { FILE *log; va_list argptr; if ((log = fopen("logfile","a+")) != NULL) { va_start(argptr); /* Makes argptr point to va_alist */ vfprintf(log,format,argptr); va_end(argptr); fclose(log); } }