Just above and below main()
FaceMan
mattl at ritcsh.csh.rit.edu
Thu Apr 11 02:19:03 AEST 1991
In article <1243 at nanometrics.UUCP> stealth at 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 at ritcsh.csh.rit.edu ! Swapping memory to disk is virtually indespensible..
mal6315 at ultb.rit.edu ! ----------------------------------------------------
mal6315 at RITVAX ! new book: "#define art of C programming..."
More information about the Comp.lang.c
mailing list