home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / std / c / 3041 < prev    next >
Encoding:
Text File  |  1992-11-19  |  2.2 KB  |  51 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!haven.umd.edu!decuac!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond
  3. From: diamond@jit345.bad.jit.dec.com (Norman Diamond)
  4. Subject: Re: Memory Usage by C
  5. Message-ID: <1992Nov20.020950.15516@nntpd.lkg.dec.com>
  6. Sender: usenet@nntpd.lkg.dec.com (USENET News System)
  7. Reply-To: diamond@jit.dec.com (Norman Diamond)
  8. Organization: Digital Equipment Corporation Japan , Tokyo
  9. References: <1992Nov19.190526.26770@den.mmc.com>
  10. Date: Fri, 20 Nov 1992 02:09:50 GMT
  11. Lines: 38
  12.  
  13. In article <1992Nov19.190526.26770@den.mmc.com> richard@crowded-house.den.mmc.com (Richard Armstrong) writes:
  14. >Are literals always stored in the same location in memory?
  15.  
  16. The standard says that identical string literals need not be distinct.
  17. In some implementations they might go in the same location; in other
  18. implementations they might not.  (It is not clear if partly identical string
  19. literals that could meaningfully overlap are also allowed to do so or not.)
  20.  
  21. >(IBM-PC,Borland)
  22.  
  23. Ask Borland.  (The standard does not require them to answer; it doesn't
  24. say that this decision is implementation-defined.  But you can always ask.)
  25.  
  26. >For instance, is the string a stored in the same place in the following
  27. >two declarations?:
  28. >static char *a[]="ABC";
  29. >funca()
  30. >{
  31. >char *a[]="ABC";
  32. >}
  33.  
  34. You cannot have two functions named funca() in the same source file, so
  35. I deleted the first one (which had nothing between the braces).  I also
  36. added a semicolon to the end of the first line.
  37.  
  38. In the first declaration, a is a static array.  When the declaration is
  39. completed, the array size is determined to be 1.  a[0] is a pointer-to-char,
  40. initially pointing to the first character in an array of 4 characters (A, B,
  41. C, and null character).  This nameless array of 4 characters is static.
  42.  
  43. In the later declaration, a is an automatic array.  This a cannot go in the
  44. same place as the first a, the static array.  This a[0] might initially
  45. point to the same static array of 4 characters that the first a[0] pointed
  46. to, or else to a different static array of 4 characters.
  47. --
  48. Norman Diamond       diamond@jit081.enet.dec.com
  49. If this were the company's opinion, I wouldn't be allowed to post it.
  50. "It's been a lovely recession."
  51.