home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!utzoo!telly!druid!darcy
- From: darcy@druid.uucp (D'Arcy J.M. Cain)
- Subject: Re: Where are literals stored?
- Message-ID: <1992Nov21.142614.11609@druid.uucp>
- Date: Sat, 21 Nov 1992 14:26:14 GMT
- References: <1992Nov18.233739.2335@den.mmc.com>
- Organization: D'Arcy Cain Consulting
- Lines: 35
-
- richard@crowded-house.den.mmc.com (Richard Armstrong) writes:
- >Are literals always stored in the same location in memory? (IBM-PC,Borland)
-
- There is a switch in the options menu to turn this on and off
-
- >For instance, is the string a stored in the same place in the following
- >two declarations?:
- >static char a[]="ABC"
- > [...]
- >char a[]="ABC";
-
- Regardless of whether the compiler merges duplicate literal strings, that
- is not what you are talking about here. These variables are not pointers
- to strings but are arrays of characters. In the first case the array is
- filled at compile time and is a unique memory location not shared by other
- locations. In the second case the array is filled at run time and may be
- implemented by a form of strcpy() and in that case the actual string copied
- may be shared with something else. However even this is not required. The
- copy in this case could be optimized to an assignment of a long to the
- location used by a and so there is no actual string in memory to be shared.
-
- In the following example the strings may be shared (if the proper switches
- are set)
-
- static char *a = "ABC";
- ...
- char *a = "ABC";
-
- Of course the variables should probably be declared const in this case.
-
- --
- D'Arcy J.M. Cain (darcy@druid.com) |
- D'Arcy Cain Consulting | There's no government
- Toronto, Ontario, Canada | like no government!
- +1 416 424 2871 DoD#0082 |
-