home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
- From: torek@horse.ee.lbl.gov (Chris Torek)
- Newsgroups: comp.lang.c
- Subject: Re: Where are literals stored?
- Date: 19 Nov 1992 18:42:06 GMT
- Organization: Lawrence Berkeley Laboratory, Berkeley
- Lines: 49
- Message-ID: <27542@dog.ee.lbl.gov>
- References: <1992Nov18.233739.2335@den.mmc.com>
- Reply-To: torek@horse.ee.lbl.gov (Chris Torek)
- NNTP-Posting-Host: 128.3.112.15
-
- In article <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?
-
- This is unspecified. The C standard allows identical literals to live
- at the same address or at differing addresses, as the implementation
- pleases.
-
- >(IBM-PC,Borland)
-
- Please try to limit system-specific questions to system-specific
- newsgroups.
-
- >For instance, is the string a stored in the same place in the following
- >two declarations?:
- >
- >static char a[]="ABC"
- >
- >funca()
- >{
- >char a[]="ABC";
- >}
-
- Neither of these is in fact a `string literal': in both cases the
- quoted strings are initializers for objects. String literals are
- formed from quoted strings that appear in a value context, e.g.,
-
- char *p, *q;
-
- p = "ABC";
- q = "ABC";
- /* it is unspecified whether p == q */
-
- Distinct objects, however, always compare unequal, thus the following
- strictly conformant program must print `0':
-
- #include <stdio.h>
- #include <stdlib.h>
-
- char a[] = "ABC";
- int main(void) {
- char b[] = "ABC";
-
- printf("%d\n", a == b);
- exit(EXIT_SUCCESS);
- }
- --
- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
- Berkeley, CA Domain: torek@ee.lbl.gov
-