[comp.lang.c] Motivation behind a particular piece of code in cpp

uday@mips.UUCP (Uday Kurkure) (11/24/87)

   I do not understand the motivation behind a following declaration
   found in the sources of cpp.

     #define STATIC

     Then there are various declartions of the sort
     STATIC char ch.

    If STATIC is defined to be null, why would one use it in declarations ?


                                         ..Uday---- 
Disclaimer: My employer and I have nothing to do with each other. It's
            strictly a business relationship.
UUCP:       uday@mips.com 
            {ames,decwrl,prls,pyramid}!mips!uday

ekrell@hector.UUCP (11/25/87)

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
>
>     Then there are various declartions of the sort
>     STATIC char ch.
>
>    If STATIC is defined to be null, why would one use it in declarations ?

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.
    
    Eduardo Krell                   AT&T Bell Laboratories, Murray Hill

    {ihnp4,seismo,ucbvax}!ulysses!ekrell

ljz@fxgrp.UUCP (Lloyd Zusman, Master Byte Software) (11/26/87)

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.

tj@alliant.UUCP (12/03/87)

In article <981@gumby.UUCP> uday@mips.UUCP (Uday Kurkure) writes:
>   I do not understand the motivation behind a following declaration
>   found in the sources of cpp.
>
>     #define STATIC
>
>     Then there are various declartions of the sort
>     STATIC char ch.
>
>    If STATIC is defined to be null, why would one use it in declarations ?

I use STATIC declarations like this in my own code to indicate variables
and routines that could be declared static.  That is, I could #define
STATIC to be static and the code would still work, because there are no
references to STATIC variables outside of the source file.

The reason I don't declare such things to be static is that global
symbols are useful for adb and gprof.

So don't think of STATIC as null; it's really a comment masquerading as
code.