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

Date: Sun, 24 Oct 1999 13:55:02 +0200
From: Marc Lehmann <pcg AT opengroup DOT org>
To: pgcc AT delorie DOT com
Subject: Re: non constant initializers
Message-ID: <19991024135502.B767@cerebro.laendle>
Mail-Followup-To: pgcc AT delorie DOT com
References: <19991023215020 DOT A5053 AT cerebro DOT laendle> <Pine DOT LNX DOT 4 DOT 10 DOT 9910232145130 DOT 3560-100000 AT Cordes DOT Phys DOT Dal DOT Ca>
Mime-Version: 1.0
In-Reply-To: <Pine.LNX.4.10.9910232145130.3560-100000@Cordes.Phys.Dal.Ca>; from Peter Cordes on Sat, Oct 23, 1999 at 10:02:40PM -0300
X-Operating-System: Linux version 2.2.12 (root AT cerebro) (gcc version 2.95.1 19990816 (release))
Sender: Marc Lehmann <pcg AT goof DOT com>
Reply-To: pgcc AT delorie DOT com
X-Mailing-List: pgcc AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Sat, Oct 23, 1999 at 10:02:40PM -0300, Peter Cordes <peter AT Cordes DOT Phys DOT Dal DOT Ca> wrote:
>  Since C doesn't do it, what is a good way to have a
> static FILE *errfile;
> in a module of a bigger program?

There isn't (in C). with gnu c you could use constructors.

> Is there a solutions which doesn't
> require an initialization routine have to be called from main() to init it
> (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

This is a bit less annoying (requiring fewer source changes):
#define errfile (errfile?errfile:stderr)

> overhead is not a big concern, since this is just for error logging.

Yeah, C does have some problems with modularization. In the old times,
however, nobody had a problem with calling 555+ initialization routines..

-- 
      -----==-                                             |
      ----==-- _                                           |
      ---==---(_)__  __ ____  __       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