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
bzs@bu-cs.bu.EDU (Barry Shein) (11/25/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---- Obviously so it could be redefined differently and re-compiled (eg. static). Just a guess but I know that CPP/PCC running on the IBM370 runs into various problems with arrays due to the 12-bit segment addressing limits, large automatics will raise this ire, statics help though oftentimes all you can do is malloc() the thing so you get code generated which uses hard addresses rather than compiler generated base/displacements. -Barry Shein, Boston University
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.
theo@natmlab.dms.oz (Theo ten Brummelaar) (11/26/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 } If STATIC is defined to be null, why would one use it in declarations ? I don't know about you but when I'm working on a large programme over the space of a few months I tend to forget what I intend for some variables. Surely this is just another way of adding comments to code. I would guess that whoever wrote the code you refer to does it for the same reason that other people use defines like ; #define FAST register #define COUNT int #define GLOBAL extern #define IMPORT extern and so on. I always thought the good thing about writting in C is that you can make it look and feel like what ever you are most comfortable with. Then again, maybe the compiler they were working on had static as default and thus did not have a keyword 'static' implimented at all. Theo ten Brummelaar ---------------------------------------------------------------------------- C.S.I.R.O. Division of Applied Physics , Linfield , Sydney , Australia. ---------------------------------------------------------------------------- Time flies like an arrow , fruit flies like an orange. ---------------------------------------------------------------------------- ACSnet: theo@natmlab CSNET: theo@natmlab.oz ARPA: theo%natmlab.oz@uunet.uu.net JANET: natmlab.oz!theo@ukc UUCP:{enea,hplabs,mcvax,prlb2,uunet,ubc-vision,ukc}!munnari!natmlab.oz!theo ----------------------------------------------------------------------------
gmp@rayssd.UUCP (11/29/87)
After reading a zillion articles about why one would want to use
STATIC, I have yet to see one suggesting it be used for the only reason
I've ever had to. Note the following:
func()
{
STATIC struct foo bar[LARGENUM];
/* do something non-recursive */
}
I have a program with a function or two in it like this that compiles
and runs fine on our VAXen and Pyramid with STATIC undefined. When the
the same code was brought to a Sun, it would not run (maybe not
compile -- don't remember now), so I defined STATIC as static and the
problem went away. (Of course, STATIC had to be added, since I don't
normally sprinkle it throughout programs.)
--
Greg Paris gmp@rayssd.ray.com
{cbosgd,gatech,ihnp4,mirror,necntc,uiucdcs,ukma,umcp-cs}!rayssd!gmp
Air can hurt you too.
mdb@laidbak.UUCP (11/29/87)
Here's a favorite one of mine. /* * Adb is more palatable when static functions and variables are * declared as globals. Lint gives more useful information when * statics are truly static. */ #ifdef lint # define STATIC static /* Declare static variables for lint */ #else /* lint */ # define STATIC /* Make static variables global for adb */ #endif /* lint */ Mark Brukhartz Lachman Associates, Inc. ..!{ihnp4, sun}!laidbak!mdb
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.