Newsgroups: comp.lang.c
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!news.cs.indiana.edu!nstn.ns.ca!uupsi!cci632!ritcsh!mattl
From: mattl@ritcsh.csh.rit.edu (FaceMan)
Subject: Re: Just above and below main()
Message-ID: <1991Apr10.161903.13778@ritcsh.csh.rit.edu>
Organization: Computer Science House @ RIT, Rochester, NY.
References: <1243@nanometrics.UUCP>
Date: Wed, 10 Apr 1991 16:19:03 GMT
Lines: 37

In article <1243@nanometrics.UUCP> stealth@nanometrics.portal.UUCP (Steve Sabram) writes:
>Ok, we got a big debate here at work about
>the folowing piece of code;
>_________________________
>
>int outside;
>
>main()
>{
>int inside;
>...
>}
>
>_________________________
>
>Just what are the differences
>between these two variables?
> 
>We all agree that "outside" is a global and thus accessable
>to all functions in this file while "inside" is accessable 
>only to everything in main().

The difference between inside and outside is where they are stored.
Since "outside" is outside of any functions, it will be allocated to main
memory. "Inside", on the other hand, is inside the function "main()", and
will be allocated on the stack. This should mean that "outside" should
start out with a value of zero (though there may be a compiler out there
that does clean out main memory for you), while inside will have an initial
value of whatever happens to be at that location on the stack (in other
words, garbage)...


-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
mattl@ritcsh.csh.rit.edu ! Swapping memory to disk is virtually indespensible..
mal6315@ultb.rit.edu     ! ----------------------------------------------------
mal6315@RITVAX           ! new book: "#define art of C programming..."
