Question

With gcc 4.6.3 (with -ansi -pedantic), I've got the following code:

// Argument counting macro
#define NARGS(...) NARGS_(__VA_ARGS__, 5, 4, 3, 2, 1)
#define NARGS_(_1, _2, _3, _4, _5, _, ...) _

static inline void fi_init_(size_t nargs, fileinfo_t *finfo, ...) {
    // Default fmt/type values
    char* fmt  = "CD";
    int   type = 1000;

    if (nargs == 2) {
        va_list  ap;
        va_start(ap, hdr);
        fmt  = va_arg(ap, char*);
        type = va_arg(ap, int);
        va_end(ap);
    } 

    // Do some junk with it
}

#define fi_init(...) fi_init_(NARGS(__VA_ARGS__)-1, __VA_ARGS__)

When called as:

fileinfo_t out; fi_init(&out);

I get a warning:

warning: ISO C99 requires rest arguments to be used

When called as:

fileinfo_t out; fi_init(&out, "CF", 2222);

I don't. How can I suppress this?

Was it helpful?

Solution

I think my problem was here:

#define NARGS(...) NARGS_(__VA_ARGS__, 5, 4, 3, 2, 1)
#define NARGS_(_1, _2, _3, _4, _5, _, ...) _ 

Changing that to:

#define NARGS(...) NARGS_(__VA_ARGS__, 5, 4, 3, 2, 1, 0)
#define NARGS_(_1, _2, _3, _4, _5, _, ...) _ 

Seems to have fixed it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top