home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16949 < prev    next >
Encoding:
Internet Message Format  |  1992-11-21  |  1.5 KB

  1. Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!spacebbs!ted.jensen
  2. From: ted.jensen@spacebbs.com (Ted Jensen) 
  3. Newsgroups: comp.lang.c
  4. Subject: Where are literals stored?
  5. Message-ID: <14446.610.uupcb@spacebbs.com>
  6. Date: 21 Nov 92 06:15:00 GMT
  7. Distribution: world
  8. Organization: SPACE BBS - Menlo Park, CA - 10 Lines + 4gB - 415-323-4193
  9. Reply-To: ted.jensen@spacebbs.com (Ted Jensen) 
  10. Lines: 38
  11.  
  12.  
  13. In message <1992Nov18.233739.2335#den.mmc.com>
  14. richard@crowded-house.den.mmc.com (Richard Armstrong) writes:
  15.  
  16. > Are literals always stored in the same location in memory?
  17. > (IBM-PC,Borland)
  18. >
  19. > For instance, is the string a stored in the same place in the
  20. > following two declarations?:
  21. >
  22. > static char a[]="ABC"
  23. > funca()
  24. > {
  25. > }
  26. >
  27. > funca()
  28. > {
  29. > char a[]="ABC";
  30. > }
  31.  
  32. I am running TC++.  Using my debugger and looking at the assembly
  33. code and data segment in each of these situations I have
  34. determined that, with my compiler:
  35.  
  36.     The "ABC" is stored in the data segment in both cases. The
  37.     difference will lie in how the compiler treats that which
  38.     lies to the left of the equal sign.  In the first case the
  39.     pointer to the string stored in the data segment is treated
  40.     as a global variable and isaccessible from functions other
  41.     than funca().  In the second case, the value of the pointer
  42.     is hardcoded in the code for the function and stored on the
  43.     stack.  That is, it is a local pointer.
  44.  
  45. Hope this helps!  Ted Jensen  Redwood City, Calif.
  46.  
  47.  
  48.  * SLMR 2.1a * 
  49.                              
  50.