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

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, May 03, 2008 at 07:43:48AM +1000, Peter Jeremy wrote:
> 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.
> 

I chose the former although I'm not sure if that is the most
appropriate place.  With this change (and few others) I have
successful built the Fortran 77 component of pcc (ie.,
ports/lang/pcc)

dhcp-78-86:kargl[206] cat h.f
      program h
      print *, 'Hello World!'
      end 
dhcp-78-86:kargl[207] ~/work/bin/f77 -v -O -o z h.f -L$HOME/work/lib

 FORTRAN 77 DRIVER, VERSION 1.11,   28 JULY 1978
h.f:
   MAIN h:
  ASM.
LOAD.
dhcp-78-86:kargl[208] ./z
 Hello World!

-- 
Steve



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