Merging of string literals guaranteed by C std?
- From: Johannes Bauer <dfnsonfsduifb@xxxxxx>
- Date: Fri, 25 May 2012 13:33:20 +0200
Hi group,
I have a question about string literals and the address that they point
to. Does the standard *guarantee* that two identical string literals
actually point to the same address. I.e. can we safely assert:
assert("foo" == "foo");
Or can it maybe only be asserted if the literal occurs in one
compilation unit (i.e. not across compilation units)?
My gut feeling tells me that I cannot rely on the addresses being
identical, but I cannot find it in N1124. It would make things much
easier/cooler if the standard would assert that in my situation, but I
don't want to rely on compiler behavior alone (gcc merges the string
literals into one address even with -O0).
Best regards,
Johannes
--
Ah, der neueste und bis heute genialste Streich unsere großenWo hattest Du das Beben nochmal GENAU vorhergesagt?Zumindest nicht öffentlich!
Kosmologen: Die Geheim-Vorhersage.
- Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1@xxxxxxxxxxxxxxxxx>
.
- Follow-Ups:
- Re: Merging of string literals guaranteed by C std?
- From: Eric Sosman
- Re: Merging of string literals guaranteed by C std?
- From: James Kuyper
- Re: Merging of string literals guaranteed by C std?
- From: Noob
- Re: Merging of string literals guaranteed by C std?
- Prev by Date: Re: possible useful macros...
- Next by Date: Re: Void variables
- Previous by thread: differentiating between pointers - "primary"?
- Next by thread: Re: Merging of string literals guaranteed by C std?
- Index(es):
Relevant Pages
|