Using stderr in an initialization?
Peter Jeremy
peterjeremy at optushome.com.au
Fri May 2 21:43:52 UTC 2008
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.
--
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-ports/attachments/20080502/7bd05bf6/attachment.pgp
More information about the freebsd-ports
mailing list