Date: Fri, 2 May 2008 13:23:56 -0700 From: Steve Kargl <sgk@troutmask.apl.washington.edu> To: freebsd-ports@freebsd.org Subject: Using stderr in an initialization? Message-ID: <20080502202356.GA67129@troutmask.apl.washington.edu>
next in thread | raw e-mail | index | archive | help
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 <stdio.h> typedef FILE *FILEP; static FILEP outfile = {stderr}; int main(int argc, char *argv[]) { FILE *fp; if (argc == 2) { fp = fopen(*++argv, "w"); outfile = fp; } fprintf(outfile, "Ouch!\n"); return 0; } 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') Yes, I know in the simple example above that I could put 'outfile = stderr' above the 'if (argc == 2)' statement. In the much more complicated code, it isn't clear where such a change be made. So, anyone have a suggestion on how to change line 5 to satisfy gcc? -- Steve
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080502202356.GA67129>