www.delorie.com/archives/browse.cgi   search  
Mail Archives: pgcc/1999/10/23/23:19:18

Date: Sat, 23 Oct 1999 22:02:40 -0300 (ADT)
From: Peter Cordes <peter AT Cordes DOT Phys DOT Dal DOT Ca>
To: pgcc AT delorie DOT com
Subject: Re: non constant initializers
In-Reply-To: <19991023215020.A5053@cerebro.laendle>
Message-ID: <Pine.LNX.4.10.9910232145130.3560-100000@Cordes.Phys.Dal.Ca>
MIME-Version: 1.0
Reply-To: pgcc AT delorie DOT com
X-Mailing-List: pgcc AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

 I speculated that this might be impossible.  I meant "impossible within
the ISO C standard".  After thinking about this for a while, I guess ISO C
disallows this because it would require the linker to support having
symbols which should have their data initialized to whatever some other
symbol has its data initialized to, after all the linking is done, or
something like that.  Since this is probably not supported by current
object file formats, it makes sense that C doesn't allow it.

 Since C doesn't do it, what is a good way to have a
static FILE *errfile;
in a module of a bigger program?  Is there a solutions which doesn't
require an initialization routine have to be called from main() to init it
to stderr, which we want to be the default for error messages.  What if
the error logging module is in a library?  Can we avoid requiring every
program which uses the library to make a call to a library init function
(if none is otherwise required)?  One solution is to have static FILE
*errfile = NULL and check for null on entry to every function which uses
it.  If null, then set it to stderr.  This is anoying, though.  At least
overhead is not a big concern, since this is just for error logging.

 Thanks,

#define X(x,y) x##y
Peter Cordes ;  e-mail: X(peter AT cordes DOT phys. , dal.ca)

On Sat, 23 Oct 1999, Marc Lehmann wrote:

> On Wed, Oct 20, 1999 at 11:51:45PM -0300, Peter Cordes <peter AT Cordes DOT Phys DOT Dal DOT Ca> wrote:
> >  Maybe it would be possible to have the compiler and linker conspire to
> > initialize outfile to stdout, but this might be impossible, because it
> 
> However, this puts a limitation on the library writers without any real
> benefit: if it doesn't break with glibc, it will break on another system.
> It's better to correct the program in question to comply with the language it
> is written in (C).
> 
> -- 
>       -----==-                                             |
>       ----==-- _                                           |
>       ---==---(_)__  __ ____  __       Marc Lehmann      +--
>       --==---/ / _ \/ // /\ \/ /       pcg AT opengroup DOT org |e|
>       -=====/_/_//_/\_,_/ /_/\_\       XX11-RIPE         --+
>     The choice of a GNU generation                       |
>                                                          |
> 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019