From owner-freebsd-ports@FreeBSD.ORG Fri May 2 21:43:52 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 3AFCA106566B for ; Fri, 2 May 2008 21:43:52 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from mail04.syd.optusnet.com.au (mail04.syd.optusnet.com.au [211.29.132.185]) by mx1.freebsd.org (Postfix) with ESMTP id BC2D18FC14 for ; Fri, 2 May 2008 21:43:51 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from server.vk2pj.dyndns.org (c122-106-215-175.belrs3.nsw.optusnet.com.au [122.106.215.175]) by mail04.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id m42Lhnu2000728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 3 May 2008 07:43:50 +1000 Received: from server.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by server.vk2pj.dyndns.org (8.14.2/8.14.1) with ESMTP id m42LhmtU067832; Sat, 3 May 2008 07:43:48 +1000 (EST) (envelope-from peter@server.vk2pj.dyndns.org) Received: (from peter@localhost) by server.vk2pj.dyndns.org (8.14.2/8.14.2/Submit) id m42Lhmxc067831; Sat, 3 May 2008 07:43:48 +1000 (EST) (envelope-from peter) Date: Sat, 3 May 2008 07:43:48 +1000 From: Peter Jeremy To: Steve Kargl Message-ID: <20080502214348.GZ7293@server.vk2pj.dyndns.org> References: <20080502202356.GA67129@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="lBqJz4CGKwlWe7/k" Content-Disposition: inline In-Reply-To: <20080502202356.GA67129@troutmask.apl.washington.edu> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.17 (2007-11-01) 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 21:43:52 -0000 --lBqJz4CGKwlWe7/k Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, May 02, 2008 at 01:23:56PM -0700, Steve Kargl wrote: >static FILEP outfile =3D {stderr}; =2E.. >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 =3D stderr; > if (argc =3D=3D 2) { =2E.. 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. --=20 Peter Jeremy Please excuse any delays as the result of my ISP's inability to implement an MTA that is either RFC2821-compliant or matches their claimed behaviour. --lBqJz4CGKwlWe7/k Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkgbixQACgkQ/opHv/APuIeU4wCfSuHthlRjSAYb0s2uwpOuo5CN iyoAni8UeDXeNhRNZfpfALTCWfRlvwLS =4NOt -----END PGP SIGNATURE----- --lBqJz4CGKwlWe7/k--