4

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
gct
  • 14,100
  • 15
  • 68
  • 107
  • I thought I understood why these occurred, but clearly I don't. I'd like to fix what I'm doing wrong if possible. – gct Jul 24 '12 at 03:36
  • By the way, this might be a duplicate of http://stackoverflow.com/questions/4100746/suppressing-iso-c99-requires-rest-arguments-to-be-used?rq=1 – LastStar007 Jul 24 '12 at 03:37
  • I saw that question, but I've got all my arguments folded into my ellipses, so I wasn't sure if I was seeing the same thing. – gct Jul 24 '12 at 03:39

1 Answers1

5

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

gct
  • 14,100
  • 15
  • 68
  • 107