From owner-freebsd-ports@FreeBSD.ORG Fri May 2 20:27:25 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 1C7561065671 for ; Fri, 2 May 2008 20:27:25 +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 EF4E08FC0C for ; Fri, 2 May 2008 20:27:24 +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 m42KNvsd067635 for ; Fri, 2 May 2008 13:23:57 -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 m42KNvxp067634 for freebsd-ports@freebsd.org; Fri, 2 May 2008 13:23:57 -0700 (PDT) (envelope-from sgk) Date: Fri, 2 May 2008 13:23:56 -0700 From: Steve Kargl To: freebsd-ports@freebsd.org Message-ID: <20080502202356.GA67129@troutmask.apl.washington.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Subject: 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 20:27:25 -0000 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 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