Logo Search packages:      
Sourcecode: gcc-2.96 version File versions

bug-68448.c

/*
 * test of vsprintf and vasprintf.
 *
 * g++ (version XXXXXX) has a problem:
 *    g++ -o test test.c
 *
 * gcc (version XXXXXX) works:
 *    gcc -o test test.c
 *
 */

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdarg.h>

#ifdef __cplusplus
}
#endif

/*
 * vsprintf wrapper.
 * works for both gcc and g++.
 */
void my_vsprintf(char *fmt, ...) {
    va_list ap;
    char buf[16385];
    int n;

    va_start(ap, fmt);
    n = vsprintf((char*)buf, (const char*)fmt, ap);
    va_end(ap);

    printf("vsprintf:\n");
    printf("n=%d\n", n);
    printf("buf=%s\n", buf);
}

/*
 * vasprintf wrapper.
 * breaks with g++.
 */
void my_vasprintf(char *fmt, ...) {
    va_list ap;
    char *buf;
    int n;

    va_start(ap, fmt);
    n = vasprintf(&buf, (const char*)fmt, ap);
    va_end(ap);

    printf("vasprintf:\n");
    printf("n=%d\n", n);
    printf("buf=%s\n", buf);
}

int main (int argc, char **argv) {
    my_vasprintf("%s %s %s", "foo", "bar", "foobar");
    my_vsprintf ("%s %s %s", "foo", "bar", "foobar");
    return 0;
}

Generated by  Doxygen 1.6.0   Back to index