Pergunta

EDIT: I now have #include <stdarg.h> and it compiles - but the varargs don't get passed. Any ideas why?


I have this code (excerpt):

void msg(char* message, ...) {
    va_list args;
    va_start(args, message);
    char* m;
    if(asprintf(&m, message, args)==-1) m = message;
    va_end(args);

    print("<fg:green>INFO:</fg> ");
    println(m);
}

(print and printf are wrappers that do the color tags)

The idea was to pass on varargs to asprintf.

However, it doesn't compile:

gcc -g -Wall -std=gnu99 -O2 -Wfatal-errors   -c -o src/ui.o src/ui.c
src/ui.c: In function ‘msg’:
src/ui.c:7:5: warning: implicit declaration of function ‘va_start’ [-Wimplicit-function-declaration]
src/ui.c:12:5: warning: implicit declaration of function ‘va_end’ [-Wimplicit-function-declaration]

Do I have to include something special to get va_start() and va_end()?


GCC (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 Xubuntu 12.04

Foi útil?

Solução

You have to include #include <stdarg.h> and use vasprintf instead of asprintf.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top