From: Petr Baudis Date: Wed, 21 Sep 2005 08:19:54 GMT Subject: Re: [PATCH] Make the git-fsck-objects diagnostics more useful Message-ID: <20050921081954.GB24902@pasky.or.cz> In-Reply-To: <200509201955.j8KJtWAr003157@laptop11.inf.utfsm.cl> Dear diary, on Tue, Sep 20, 2005 at 09:55:32PM CEST, I got a letter where Horst von Brand told me that... > > +static void objreport(struct object *obj, const char *severity, > > + const char *err, va_list params) > > +{ > > + fprintf(stderr, "%s in %s %s: ", > > + severity, obj->type, sha1_to_hex(obj->sha1)); > > + vfprintf(stderr, err, params); > > + fputs("\n", stderr); > > +} > > Is this legal? I am under the impression you have to call > va_start()/va_end() always, even if you just pass the va_list down. va_list will probably be/contain some pointer, and with va_start() you "seed" it to point at the stack after the given parameter and slurp the additional function parameters from there. If you already have it initialized, va_start() makes no sense. > The comp.lang.c FAQ agrees > with me here... it should be: That says nothing about passing va_list down. > static void objreport(struct object *obj, const char *severity, > const char *err, ...) > { > va_list params; > > fprintf(stderr, "%s in %s %s: ", > severity, obj->type, sha1_to_hex(obj->sha1)); > va_start(params, err); > vfprintf(stderr, err, params); > va_end(params); > fputs("\n", stderr); > } How do you then call objreport() ? params would contain another va_list if you called it the same as before, which would probably surprise vfprintf() a bit. BTW, we do the same in usage.c. -- Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ VI has two modes: the one in which it beeps and the one in which it doesn't.