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 1743
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 variables by placing them at the same
address (my g++ compiler does this). Therefore the output of the given
C program is compiler dependent. What is worse, the program does not
do what its writer most likely intended, since, std::set's find()...
|
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:
overwrite of charcter in constatnt string like char *str="Hi
all"; str='A'; the result of this str points to the string "Hi All"
|
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 is that the hashcode can
change depending ion the clr version, from msdn
'The behavior of GetHashCode is dependent on its implementation, which
might change from one version of the common language runtime to
another. A reason why this might happen...
|
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 accident" etc...)
The issue appears possibly to point to a bug in the Python compiler,
with it producing inconsistent results. I'm using "Python 2.4.2 (#67,
Sep 28 2005, 12:41:11) on win32".
This code sometimes produces a float of 1.0, sometimes...
|
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |