dmb@wam.umd.edu (David M. Baggett) (05/01/91)
In article <1991Apr30.183034.15773@lsuc.on.ca> jimomura@lsuc.on.ca (Jim Omura) writes: > I've never seen this type of declaration before. Why would you >bother to declare a "global" as a "static"? Is there any point to >it? It doesn't seem to be a problem for the compilers to handle. Oops, I forgot one crucial point in my previous message. If you declare a global variable as "static" then it will not be exported out of the .o file it appears in. So static vs. auto makes a difference with respect to separate compilation. The static storage class is very useful for avoiding name clashes between modules. If you're not using separate compilation; i.e., if you have one giant .c file or #include everything all at once, then static vs. auto makes little difference for globals. Dave Baggett dmb%wam.umd.edu@uunet.uu.net
jimomura@lsuc.on.ca (Jim Omura) (05/02/91)
In article <1991May1.020731.16272@wam.umd.edu> dmb@wam.umd.edu (David M. Baggett) writes: >In article <1991Apr30.183034.15773@lsuc.on.ca> jimomura@lsuc.on.ca (Jim Omura) writes: >> I've never seen this type of declaration before. Why would you >>bother to declare a "global" as a "static"? Is there any point to >>it? It doesn't seem to be a problem for the compilers to handle. > >Oops, I forgot one crucial point in my previous message. If you >declare a global variable as "static" then it will not be exported out >of the .o file it appears in. So static vs. auto makes a difference >with respect to separate compilation. The static storage class is >very useful for avoiding name clashes between modules. >If you're not using separate compilation; i.e., if you have one >giant .c file or #include everything all at once, then static >vs. auto makes little difference for globals. Many thanks to all who have replied to my query! After reading this message I remembered all about "static globals". Ironically, I learned it years ago and forgot about it a couple of years ago and asked exactly the same question at that time. Then I remembered when someone else answered. So here I am about 2 years later asking it all over again. Truth is, I'll probably forget and have to ask again in another couple of years. Gads. No hope for me at all. :-) -- Jim Omura, 2A King George's Drive, Toronto, (416) 652-3880 lsuc!jimomura Byte Information eXchange: jimomura
dc@presto.ruhr.de (David Channing) (05/03/91)
In article <1991May1.020731.16272@wam.umd.edu> dmb@wam.umd.edu (David M. Baggett) writes: > > If you're not using separate compilation; i.e., if you have one > giant .c file or #include everything all at once, then static > vs. auto makes little difference for globals. Unless of course your global variable names conflict with names in the library, in which case you would want to make them static. -- dc@presto.ruhr.sub.org dc@presto.ruhr.de