Tuesday, January 13, 2026

va_list and cproc

Hi, I am trying to use cproc[1] under OpenBSD 7.8 release, and I
noticed that this test program

#include <stdarg.h>
#include <stdio.h>

void
printout(char* fmt, int dummy, ...)
{
va_list ap;
char buf[4096];
va_start(ap, dummy);
vsnprintf(buf, 4096, fmt, ap);
printf("%s\n", buf);
va_end(ap);
}

int
main(int argc, char** argv)
{
printout("Hello, %s world!", 0, "brave GNU");
}

fails to compile, giving

test.c:9:33: error: base types of pointer assignment must be
compatible or void

after reporting this to cproc ticket tracker[2], I got a suggestion to
provide the output[3] from preprocessing the source,

cproc -E test.c

it so happens that if __GNUC__ is not defined (which is the case in
cproc), __va_list is defined as char *, which explains the error, since
the declaration of vsnprintf is

int vsnprintf(char * __restrict, size_t, const char * __restrict,
__va_list);

va_list is defined as __builtin_va_list, and
char * !== __builtin_va_list, so va_list !== __va_list.


1. Is there a reason that #if !(defined(__GNUC__) && __GNUC__ >= 3),
__va_list is defined as char *?

2. Would it be possible to support cproc by defining __va_list as
__builtin_va_list in _types.h?


Thanks in advance,
Strahinya


[1]: https://sr.ht/~mcf/cproc/
[2]: https://todo.sr.ht/~mcf/cproc/96
[3]: https://0x0.st/PXEU.txt

No comments:

Post a Comment