Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Var Args are funky

Name: Anonymous 2007-05-21 0:19 ID:vdiiFf1F

When I did a return from va_arg(args, void *), it always seems to return null even though there are more arguments remaining. In this case, the arg list is filled with vars that need to be free'd prior to exiting the program. Anyone know why such an unsightly approach is needed?

int cp_error(const char *msg, int varc, ...) {
    int varg = 0;
    va_list args;

    if (varc > 0) {
        varg = 1;
        va_start(args, msg);
    }

    while (--varc >= 0) {
        va_arg(args, void *);
        free( (void *) *((char **) args) );
    }

    if (varg) {
        va_end(args);
    }

    fprintf(stdout, "%s\n", msg);

    return 0;
}

Name: Anonymous 2007-05-21 12:51 ID:vdiiFf1F

>>9
Well, I've tested it over and over and it only frees things correctly when I use the code I put up top. If I do it your way, it crashes.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List