I always consider that the constant character strings of which
literal value are the same lay out at the same logic address, in
another words, every constant character string have only one copy in
the program. My view base on that if it doesn't that, you lose the
memory of the string that you have used except store the address in a
pointer, this is a form of memory leak although it doesn't really eat
the memory as the general memory leak. The x86 machine always support
my view:-)
But recently someone told me that the addresses of the same character
strings are not the same in SunOS, so it seems that how to lay out the
constant strings is complier dependent. If it's true, I wonder the
reason why my view is wrong? Both informations and links are
appreciated. Thanks to all!
Best Regards 4 1729
Quentin Yuan wrote:
I always consider that the constant character strings of which
literal value are the same lay out at the same logic address, in
another words, every constant character string have only one copy in
the program. My view base on that if it doesn't that, you lose the
memory of the string that you have used except store the address in a
pointer, this is a form of memory leak although it doesn't really eat
the memory as the general memory leak. The x86 machine always support
my view:-)
But recently someone told me that the addresses of the same character
strings are not the same in SunOS, so it seems that how to lay out the
constant strings is complier dependent. If it's true, I wonder the
reason why my view is wrong? Both informations and links are
appreciated. Thanks to all!
A C implementation is allowed, but not required, to collapse identical
string literals (and parts thereof).
While it's /nice/ to be able to save space this way, it does require
a certain amount of sophistication in the implementation -- the linker
(or its equivalent) must be able to identify the equal areas /and know
that it can collapse them/. Some linkers don't have the language to be
told that.
It would not surprise me if an implementation shared literals in the
same compilation unit even if it couldn't do so across units.
--
"Possibly you're not recalling some of his previous plans." Zoe, /Firefly/
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
Chris Dollin wrote:
Quentin Yuan wrote:
> I always consider that the constant character strings of which literal value are the same lay out at the same logic address, in another words, every constant character string have only one copy in the program. My view base on that if it doesn't that, you lose the memory of the string that you have used except store the address in a pointer, this is a form of memory leak although it doesn't really eat the memory as the general memory leak. The x86 machine always support my view:-) But recently someone told me that the addresses of the same character strings are not the same in SunOS, so it seems that how to lay out the constant strings is complier dependent. If it's true, I wonder the reason why my view is wrong? Both informations and links are appreciated. Thanks to all!
A C implementation is allowed, but not required, to collapse identical
string literals (and parts thereof).
While it's /nice/ to be able to save space this way, it does require
a certain amount of sophistication in the implementation -- the linker
(or its equivalent) must be able to identify the equal areas /and know
that it can collapse them/. Some linkers don't have the language to be
told that.
It would not surprise me if an implementation shared literals in the
same compilation unit even if it couldn't do so across units.
Also, some implementations choose to make string literals'
arrays writeable in support of old and now-disparaged API's like
mktemp().[*] Clearly, a literal array that is modifiable cannot
be combined with other supposedly-identical arrays, because the
similarity of their content may be temporary.
[*] Yes, I'm aware that it is possible to use mktemp() in
a way that doesn't rely on modifying literal arrays. But the
bald fact is that existing code frequently applies mktemp() to
a literal -- and what's the implementor to do, get involved in
a blame game with the broken code? The old rhyme about the
driver who "died defending his right of way" comes to mind.
--
Eric Sosman es*****@acm-dot-org.invalid
Eric Sosman said:
<snip>
[*] Yes, I'm aware that it is possible to use mktemp() in
a way that doesn't rely on modifying literal arrays. But the
bald fact is that existing code frequently applies mktemp() to
a literal -- and what's the implementor to do, get involved in
a blame game with the broken code? The old rhyme about the
driver who "died defending his right of way" comes to mind.
Various versions exist. One rendition goes like this:
Here lie the bones of Solomon Gray,
Who died defending his right of way.
He was right, dead right, as he sped along,
But just as dead as if he'd been wrong.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www.
Richard Heathfield wrote:
Eric Sosman said:
<snip>
>[*] Yes, I'm aware that it is possible to use mktemp() in a way that doesn't rely on modifying literal arrays. But the bald fact is that existing code frequently applies mktemp() to a literal -- and what's the implementor to do, get involved in a blame game with the broken code? The old rhyme about the driver who "died defending his right of way" comes to mind.
Various versions exist. One rendition goes like this:
Here lie the bones of Solomon Gray,
Who died defending his right of way.
He was right, dead right, as he sped along,
But just as dead as if he'd been wrong.
A search on "defending his right of way" turns up Justin Gray,
old John Gray, Solomon Gray, John O'Day, Captain Grey, Sammy Jay,
Daniel Day (with a rather different closing couplet), Mike O'Day,
William Jay, Mike O'Dea, Paddy O'Shea, John Day (sloppy scansion),
Stubborn O'Day (still sloppier scansion), Justin Grey, Captain Oday,
old John Jay, Johnathan Gray, Roger O'Day, and enough others to
diminish desire for dactyls.
Lurching, nay, reeling towards topicality: The bewildering
assortment of competing variants, each with its supporters, is
reminiscent of the situation confronting the writers of the
original ANSI C Standard.
--
Eric Sosman es*****@acm-dot-org.invalid This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Neil Zanella |
last post by:
Hello,
Consider the following program. There are two C style string stack variables
and one C style string heap variable. The compiler may or may not optimize
the space taken up by the two stack...
|
by: Mantorok Redgormor |
last post by:
Is const really constant?
And on an OT note: how can I post with a modified e-mail address so I
don't get so much spam?
|
by: Ramaraj M Bijur |
last post by:
Hi All,
Could anyone help me to resolve following problem in C the IDE used is
Microsoft VC++,
Please let me know the which option in VC++ will do the needful
The problem statement:...
|
by: Nick |
last post by:
Hi all,
I am using GetHashCode on unique strings to get a unique integer for a
string that I can then place into a database (use int rather than the
string to make indexing faster). The problem...
|
by: Chakkaradeep |
last post by:
Hi all,
i have a string,
str_old="E:\a\b\c.exe",
and i want to change to
str_new="E:\\a\\b\\c.exe".
|
by: devdatta_clc |
last post by:
Hi C experts
I've a bunch of questions.
Consider this simplified piece of code.
const int a = 10;
int main () {
static int b = a;
|
by: Peter Hansen |
last post by:
I'm investigating a puzzling problem involving an attempt to generate a
constant containing an (IEEE 754) "infinity" value. (I understand that
special float values are a "platform-dependent...
|
by: mallikaarjuna24 |
last post by:
I am not restricted from doing an assignment operation on a constant
datatype ( say, an int ) but just warned of the consequence. why?
|
by: aarklon |
last post by:
Hi all,
what exactly is the purpose of multi-character constant..???
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |