Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site birtch.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!ittatc!dcdwest!sdcsvax!sdcrdcf!trwrb!scgvaxd!felix!birtch!oleg From: oleg@birtch.UUCP (Oleg Kiselev x268) Newsgroups: net.lang.c Subject: Re: Forward Referencing of Static Variables OK? Message-ID: <185@birtch.UUCP> Date: Wed, 16-Oct-85 01:40:53 EDT Article-I.D.: birtch.185 Posted: Wed Oct 16 01:40:53 1985 Date-Received: Sat, 19-Oct-85 07:54:31 EDT References: <365@tekcbi.UUCP> <268@ssc-vax.UUCP> Organization: Birtcher, Santa Ana, Ca. Lines: 48 > From the way I read K&R, the "static" keyword is redundant, unless > it is inside a function. In other words, "static int thing;" is > equivalent to "int thing;" unless the declaration takes place inside > a function. (Any comment on that??) > Yes! "static" means that only the file where the "static thing" is declared will know about it! It's usefull for doing data hiding and modular a la Ada developement ( Thanks to Dan Berry for teaching how to do it right!) > For instance, if file a.h has the > declaration "int thing;", and a.h is included by b.c and c.c, does > b.c access the same "thing" that c.c does? I don't think that K&R > specify. And if the declaration is "extern int thing" then there must > still be a further declaration of "thing" somewhere else. (Anybody > got anything else to say???) As a matter of fact! Yes they do. The linker takes care of resolving this type of reference. If you have ever written a linker you'd know! As long as we are at it : if a.h declares "static thing" and is included by b.c and c.c, b.c and c.c see different things. And if b.c declares "static <> thing;" and c.c "extern <> thing" linker will complain about undefined "_c" in c.c! Also, if you have "extern <> thing" and "static <> thing" static declaration supercedes the external and is the one seen in the file. And equivalent "extern" and "auto" declarations are mapped into the same location. And, yes, declaring the same variable two different types is a no-no in the same file. > Lowell Savage -- -----------------------------------+ With deep indifference, "I disbelieve an army of invisible | Oleg Kiselev. mind-flayers!" | DISCLAIMER: "OK. They are *still* not there." | I don't know what I am talking about and -----------------------------------+ therefore am not responsible for any damages to people who take me seriously! ...!trwrb!felix!birtch!oleg ...!{ihnp4|randvax}!ucla-cs!uclapic!oac6!oleg Nothing I ever say reflects the views or opinions of my employers. They knew who they hired though!