From owner-freebsd-ports@FreeBSD.ORG Fri May 2 22:50:17 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 5329D106567D for ; Fri, 2 May 2008 22:50:17 +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 1566E8FC25 for ; Fri, 2 May 2008 22:50:17 +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 m42Mkmta068703; Fri, 2 May 2008 15:46:48 -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 m42Mkmil068702; Fri, 2 May 2008 15:46:48 -0700 (PDT) (envelope-from sgk) Date: Fri, 2 May 2008 15:46:48 -0700 From: Steve Kargl To: Peter Jeremy Message-ID: <20080502224648.GA68629@troutmask.apl.washington.edu> References: <20080502202356.GA67129@troutmask.apl.washington.edu> <20080502214348.GZ7293@server.vk2pj.dyndns.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080502214348.GZ7293@server.vk2pj.dyndns.org> 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 22:50:17 -0000 On Sat, May 03, 2008 at 07:43:48AM +1000, Peter Jeremy wrote: > On Fri, May 02, 2008 at 01:23:56PM -0700, Steve Kargl wrote: > >static FILEP outfile = {stderr}; > ... > >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') > > The braces are superfluous but the underlying problem is that stderr > is not a compile-time constant - it's an 'extern FILE *'. > > >clear where such a change be made. So, anyone have a > >suggestion on how to change line 5 to satisfy gcc? > > Move the assignment to the start of main(): > >int > >main(int argc, char *argv[]) > >{ > > FILE *fp; > > > outfile = stderr; > > if (argc == 2) { > ... > > If 'outfile' is not visible from main() then you'll need to use some > sort of initialisation function - either called explicitly from main() > or via an C++-style implicitly-called initialiser. > I chose the former although I'm not sure if that is the most appropriate place. With this change (and few others) I have successful built the Fortran 77 component of pcc (ie., ports/lang/pcc) dhcp-78-86:kargl[206] cat h.f program h print *, 'Hello World!' end dhcp-78-86:kargl[207] ~/work/bin/f77 -v -O -o z h.f -L$HOME/work/lib FORTRAN 77 DRIVER, VERSION 1.11, 28 JULY 1978 h.f: MAIN h: ASM. LOAD. dhcp-78-86:kargl[208] ./z Hello World! -- Steve