Re: Compiling Error
> Date: Wed, 22 Mar 2000 14:55:58 +0100
> From: Marcus Brinkmann <Marcus.Brinkmann@ruhr-uni-bochum.de>
> To: Michal Fecanin Araujo <fecanin@cma.ulpgc.es>
> Cc: Debian Development List <debian-devel@lists.debian.org>
> Subject: Re: Compiling Error
>
> On Wed, Mar 22, 2000 at 01:15:01PM +0000, Michal Fecanin Araujo wrote:
> > ------------------------------------------------------
> > #include <stdio.h>
> >
> > FILE *output=stderr;
> >
> > int main()
> > {
> > fprintf(output,"Hello World\n");
> > }
> > ------------------------------------------------------
> >
> > The problem is that its not possible to initialize output with stderr
> > because it is not a constant. Is there any solution to this without
> > modification of the code, only with gcc options.
>
> No. Your code is invalid, and it should be fixed. You already know the fix.
> Now you just have to accept it.
This is an interesting problem which was raised on the pgcc mailing list
last year. Check out my reply to someone's question:
http://www.delorie.com/archives/browse.cgi?p=pgcc/1999/10/23/23:19:18
and Marc Lehmann's answer:
http://www.delorie.com/archives/browse.cgi?p=pgcc/1999/10/24/19:18:25
summary: C is annoying like that, but if you want to have
static FILE *errfile = stderr;
in a library, but have it be legal C (!), you can use GNU C constructors, or
you can
static FILE *errfile = NULL;
#define errfile (errfile?errfile:stderr)
This is easier than explicitly checking at the top of every function which
uses it. I ran into this problem when hacking the Linux-lab-project
<http://www.llp.fu-berlin.de/> GPIB drivers for a glibc 2.1 system (rh6.0).
--
#define X(x,y) x##y
DUPS Secretary ; http://is2.dal.ca/~dups/
Peter Cordes ; e-mail: X(peter@cordes.phys. , dal.ca)
"The gods confound the man who first found out how to distinguish the hours!
Confound him, too, who in this place set up a sundial, to cut and hack
my day so wretchedly into small pieces!" -- Plautus, 200 BCE
Reply to: