Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 May 2008 07:43:48 +1000
From:      Peter Jeremy <peterjeremy@optushome.com.au>
To:        Steve Kargl <sgk@troutmask.apl.washington.edu>
Cc:        freebsd-ports@freebsd.org
Subject:   Re: Using stderr in an initialization?
Message-ID:  <20080502214348.GZ7293@server.vk2pj.dyndns.org>
In-Reply-To: <20080502202356.GA67129@troutmask.apl.washington.edu>
References:  <20080502202356.GA67129@troutmask.apl.washington.edu>

next in thread | previous in thread | raw e-mail | index | archive | help

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080502214348.GZ7293>