From owner-freebsd-ia64@FreeBSD.ORG Thu Apr 22 08:49:42 2004 Return-Path: Delivered-To: freebsd-ia64@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D22AA16A4D0 for ; Thu, 22 Apr 2004 08:49:42 -0700 (PDT) Received: from TRANG.nuxi.com (trang.nuxi.com [66.93.134.19]) by mx1.FreeBSD.org (Postfix) with ESMTP id 815D943D48 for ; Thu, 22 Apr 2004 08:49:42 -0700 (PDT) (envelope-from obrien@NUXI.com) Received: from dragon.nuxi.com (obrien@localhost [127.0.0.1]) by TRANG.nuxi.com (8.12.11/8.12.10) with ESMTP id i3MFnfrN091364 for ; Thu, 22 Apr 2004 08:49:41 -0700 (PDT) (envelope-from obrien@dragon.nuxi.com) Received: (from obrien@localhost) by dragon.nuxi.com (8.12.11/8.12.11/Submit) id i3MFnfZS091363 for ia64@freebsd.org; Thu, 22 Apr 2004 08:49:41 -0700 (PDT) (envelope-from obrien) Date: Thu, 22 Apr 2004 08:49:41 -0700 From: "David O'Brien" To: ia64@freebsd.org Message-ID: <20040422154941.GD78422@dragon.nuxi.com> References: <20040421155127.GS57650@netch.kiev.ua> <20040421165307.GB832@ns1.xcllnt.net> <20040422044543.GA78422@dragon.nuxi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040422044543.GA78422@dragon.nuxi.com> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 5.2-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 Subject: Re: va_list q X-BeenThere: freebsd-ia64@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: ia64@freebsd.org List-Id: Porting FreeBSD to the IA-64 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Apr 2004 15:49:43 -0000 On Wed, Apr 21, 2004 at 09:45:43PM -0700, David O'Brien wrote: > On Wed, Apr 21, 2004 at 09:53:07AM -0700, Marcel Moolenaar wrote: > > On Wed, Apr 21, 2004 at 06:51:27PM +0300, Valentin Nechayev wrote: > > The use of va_arg(args, va_list) works on ia64 (FreeBSD, HP-UX and Linux). > > Given the limited context, I can only suggest that you try to create a > > temporary variable of type va_list and change the offending line to: > > > > va_list tmpvalist = va_arg(args, va_list); > > n = vslprintf(buf, buflen + 1, f, tmpvalist); > ..snip.. > > #include > > #include > > > > int > > vf2(int count, va_list ap) > > > Still wrong: > > sledge$ cc arg.c > sledge$ ./a.out > Segmentation fault (core dumped) > > your test program isn't ISO-C compliant. The details: This code breaks because it is not ISO-C compliant. Marcel's suggestion also isn't ISO-C compliant. One must use va_copy() just like one needs to use strcpy() to get a unique copy of a C string. There are two platforms to date where GCC takes "advantage" of the ISO-C99 standard and impliments stdargs in a way that depends on compliant code. Note that the "#ifdef __powerpc__" code is ISO-C compliant and should work on all platforms. 1. Adhere to ISO C specification for stdargs: Do not copy ap directly: void foo (va_list ap) { va_list tap = ap; /* use tap */ } Correct usage: #include void foo (va_list ap) { va_list tap; va_copy (tap, ap); /* use tap */ } GCCs ap is a pointer for AMD64. &ap does not do what you may expect. Review ISO C99 standard, Section 7.15. -- -- David (obrien@FreeBSD.org)