Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!fxgrp!ljz
From: ljz@fxgrp.UUCP (Lloyd Zusman, Master Byte Software)
Newsgroups: comp.unix.wizards,comp.lang.c
Subject: Re: Motivation behind a particular piece of code in cpp
Message-ID: <170@fxgrp.UUCP>
Date: Wed, 25-Nov-87 16:53:16 EST
Article-I.D.: fxgrp.170
Posted: Wed Nov 25 16:53:16 1987
Date-Received: Sun, 29-Nov-87 02:20:08 EST
References: <981@gumby.UUCP> <3218@ulysses.homer.nj.att.com>
Reply-To: fxgrp!ljz@ames.arpa (Lloyd Zusman, Master Byte Software)
Followup-To: <3218@ulysses.homer.nj.att.com> ekrell@hector (Eduardo Krell)
Organization: FX Development Group, Inc., Mountain View, CA
Lines: 73
Keywords: cpp, static, STATIC
Xref: mnetor comp.unix.wizards:5624 comp.lang.c:5579

In article <3218@ulysses.homer.nj.att.com> ekrell@hector (Eduardo Krell) writes:
>In article <981@gumby.UUCP> uday@mips.UUCP writes:
>
>>   I do not understand the motivation behind a following declaration
>>   found in the sources of cpp.
>>
>>     #define STATIC
>> ...
>
>My guess is that you could change the #define line to
>
>#define STATIC static
>
>and then make all those variables static without having to change
>each individual declaration.
> ...

I've actually seen this used with a different twist:

Assume that there are three files:  vars.h, main.c, sub.c

/*** contents of vars.h ***/

STATIC int foo;
STATIC char *bar;

/*** end of vars.h ***/


/*** contents of main.c ***/

#define STATIC

#include "vars.h"
      .
      .
      .
/*** end of main.c ***/


/*** contents of sub.c ***/

#define STATIC extern

#include "vars.h"
      .
      .
      .
/*** end of sub.c ***/


This allows one include file to be used both for defining global
variables in one compiland and for containing the external references
to those same variables in other compilands.  I think it's a bit
misleading to use the word STATIC for this, as a word like GLOBAL
might be better.  But I've actually seen the word STATIC used just
like this in some existing unix code (it might have been the source
for yacc or lex ...  I don't remember for sure).


-------------------------------------------------------------------------
 Lloyd Zusman
 Master Byte Software
 Los Gatos, California
 "We take things well in hand."        UUCP:   ...!ames!fxgrp!ljz

 NOTE:  It's difficult to reach this site.  If you've sent mail to me
	and not gotten a reply, it's probably because the net couldn't
        find this site and I never got your note.  Mailing to this site
        will yield best results if you explicitly enter a UUCP path name
        (as shown above) instead of counting on your news poster or on
        your "sendmail" to handle things properly.  Any help with net
        paths to 'ames' (the only feed to my site) would be greatly
        appreciated.  Sorry for the inconvenience.