home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!spacebbs!ted.jensen
- From: ted.jensen@spacebbs.com (Ted Jensen)
- Newsgroups: comp.lang.c
- Subject: Where are literals stored?
- Message-ID: <14446.610.uupcb@spacebbs.com>
- Date: 21 Nov 92 06:15:00 GMT
- Distribution: world
- Organization: SPACE BBS - Menlo Park, CA - 10 Lines + 4gB - 415-323-4193
- Reply-To: ted.jensen@spacebbs.com (Ted Jensen)
- Lines: 38
-
-
- In message <1992Nov18.233739.2335#den.mmc.com>
- richard@crowded-house.den.mmc.com (Richard Armstrong) writes:
-
- > Are literals always stored in the same location in memory?
- > (IBM-PC,Borland)
- >
- > For instance, is the string a stored in the same place in the
- > following two declarations?:
- >
- > static char a[]="ABC"
- > funca()
- > {
- > }
- >
- > funca()
- > {
- > char a[]="ABC";
- > }
-
- I am running TC++. Using my debugger and looking at the assembly
- code and data segment in each of these situations I have
- determined that, with my compiler:
-
- The "ABC" is stored in the data segment in both cases. The
- difference will lie in how the compiler treats that which
- lies to the left of the equal sign. In the first case the
- pointer to the string stored in the data segment is treated
- as a global variable and isaccessible from functions other
- than funca(). In the second case, the value of the pointer
- is hardcoded in the code for the function and stored on the
- stack. That is, it is a local pointer.
-
- Hope this helps! Ted Jensen Redwood City, Calif.
-
-
- * SLMR 2.1a *
-
-