From owner-freebsd-ports@FreeBSD.ORG Fri May 2 20:57:20 2008 Return-Path: Delivered-To: freebsd-ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0D235106566B for ; Fri, 2 May 2008 20:57:20 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.208.78.105]) by mx1.freebsd.org (Postfix) with ESMTP id DDFCA8FC18 for ; Fri, 2 May 2008 20:57:19 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.2/8.14.2) with ESMTP id m42Krp5n067863; Fri, 2 May 2008 13:53:51 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.2/8.14.2/Submit) id m42Krpjv067862; Fri, 2 May 2008 13:53:51 -0700 (PDT) (envelope-from sgk) Date: Fri, 2 May 2008 13:53:51 -0700 From: Steve Kargl To: Bakul Shah Message-ID: <20080502205351.GA67671@troutmask.apl.washington.edu> References: <20080502202356.GA67129@troutmask.apl.washington.edu> <20080502204355.6349B5B3B@mail.bitblocks.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080502204355.6349B5B3B@mail.bitblocks.com> User-Agent: Mutt/1.4.2.3i Cc: freebsd-ports@freebsd.org Subject: Re: Using stderr in an initialization? X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 May 2008 20:57:20 -0000 On Fri, May 02, 2008 at 01:43:55PM -0700, Bakul Shah wrote: > On Fri, 02 May 2008 13:23:56 PDT Steve Kargl wrote: > > I'm porting a piece of code to FreeBSD, and I've run into > > a problem that I currently don't know how to solve. I scanned > > both the Porter's Handbook and the Developer's Handbook, but > > came up empty. > > > > A reduce testcase is > > > > #include > > > > typedef FILE *FILEP; > > > > static FILEP outfile = {stderr}; > > > ... > > GCC gives > > > > troutmask:sgk[204] cc -o z a.c > > a.c:5: error: initializer element is not constant > > a.c:5: error: (near initialization for 'outfile') > > > > So, anyone have a > > suggestion on how to change line 5 to satisfy gcc? > > It *used* to be the case that stderr was a macro referring to > something like &_iob[2] which is a link time constant > expression. As per section 7.19.1 in the C standard, the > stderr macro is an expression of type `pointer to file' but > not a constant. You wouldn't expect the following to work, > would you? > > FILE* f; > FILE* outfile = f; > > It is the exact same thing. But you can do > > static FILE** _outfile = &stderr; > #define outfile (*_outfile) > > to achive the effect you want. Thanks for the suggestion. This is K&R era code, and if I read the dates in comments correctly, it predates the formation of the ANSI C standard committee by more than 4 years. -- Steve