From owner-freebsd-amd64@FreeBSD.ORG Wed Feb 16 06:05:12 2005 Return-Path: Delivered-To: freebsd-amd64@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7629516A4CE; Wed, 16 Feb 2005 06:05:12 +0000 (GMT) Received: from dragon.nuxi.com (trang.nuxi.com [66.93.134.19]) by mx1.FreeBSD.org (Postfix) with ESMTP id 10E0543D31; Wed, 16 Feb 2005 06:05:12 +0000 (GMT) (envelope-from obrien@NUXI.com) Received: from dragon.nuxi.com (obrien@localhost [127.0.0.1]) by dragon.nuxi.com (8.13.1/8.13.1) with ESMTP id j1G656NZ007148; Tue, 15 Feb 2005 22:05:11 -0800 (PST) (envelope-from obrien@dragon.nuxi.com) Received: (from obrien@localhost) by dragon.nuxi.com (8.13.1/8.13.1/Submit) id j1G656WP007147; Tue, 15 Feb 2005 22:05:06 -0800 (PST) (envelope-from obrien) Date: Tue, 15 Feb 2005 22:05:06 -0800 From: "David O'Brien" To: Pav Lucistnik Message-ID: <20050216060506.GA2900@dragon.nuxi.com> References: <1108516561.1564.4.camel@hood.oook.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1108516561.1564.4.camel@hood.oook.cz> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 6.0-CURRENT Organization: The NUXI BSD Group X-Pgp-Rsa-Fingerprint: B7 4D 3E E9 11 39 5F A3 90 76 5D 69 58 D9 98 7A X-Pgp-Rsa-Keyid: 1024/34F9F9D5 cc: freebsd-amd64@FreeBSD.org Subject: Re: va_list fun X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: freebsd-amd64@FreeBSD.org List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Feb 2005 06:05:12 -0000 On Wed, Feb 16, 2005 at 02:16:01AM +0100, Pav Lucistnik wrote: > Someone please explain to me what I'm doing wrong: > > [legrace.c] > #include > #include > > void funny(char *format, ...) { > va_list ap; > > va_start(ap, format); > vfprintf(stdout, format, ap); > vfprintf(stdout, format, ap); > vfprintf(stdout, format, ap); > vfprintf(stdout, format, ap); > vfprintf(stdout, format, ap); > va_end(ap); > } You've consumed the 'ap' after the first vfprintf() can cannot resuse it. You need to read the ISO C 1999 standard 7.15. With all GCC supported platforms except PowerPC, and now AMD64 you can get away with va_list copies via a simple '=' assignment. Now when you want a copy you either have to use va_copy() [think about why you have to use strcpy for two 'char *' vs. '=']. Or, va_end and do another va_start, which would be cleaner in your case. See /usr/src/sbin/dump/optr.c:msg() for an example of the correct way to do it. -- -- David (obrien@FreeBSD.org)