Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC no longer implements <varargs.h>

I have to change this code fragment from varargs.h to stdarg.h, but I do not know exactly how to:

#ifndef lint
int ll_log (va_alist)
va_dcl
{
    int event, result;
    LLog   *lp;
    va_list ap;

    va_start (ap);

    lp = va_arg (ap, LLog *);
    event = va_arg (ap, int);

    result = _ll_log (lp, event, ap);

    va_end (ap);

    return result;
}

When I try build this, compiler says:

error "GCC no longer implements <varargs.h>."
error "Revise your code to use <stdarg.h>."

The program, which I need to compile and run, has a few similar fragments and I need to know how to change them. If you can write some example, I'll be content.

like image 919
DarthBoa Avatar asked Jul 25 '14 07:07

DarthBoa


2 Answers

<varargs.h> is a pre-standard C header; use <stdarg.h> instead. The differences:

  1. The function must take at least one named argument.
  2. The function must be prototyped (using the ellipsis terminator).
  3. The va_start macro works differently: it takes two arguments, the first being the va_list to be initialized and the second the name of the last named argument.

Example:

int ll_log (LLog *llog, ...) {
    int event, result;
    LLog   *lp;
    va_list ap;

    va_start (ap, llog);

    lp = llog;
    event = va_arg (ap, int);

    result = _ll_log (lp, event, ap);

    va_end (ap);
    return result;
}

Regarding va_start: gcc ignores the second argument, but not giving the correct one is not portable.

like image 176
mafso Avatar answered Sep 28 '22 07:09

mafso


You have to include

#include <stdarg.h>

va_ Macro syntax stays the same.

like image 30
this Avatar answered Sep 28 '22 06:09

this