Click to See Complete Forum and Search --> : address of constant


George2
November 15th, 2007, 02:20 AM
Hello everyone,


I have tried that even if I have multiple character pointer variables, if the content they pointed to are the same, they are allocated with the same value. So, I think from compiler point of view, the constant with the same content shares the single copy in memory?

Here is my test program in Visual Studio 2005.


#include <windows.h>

int main (int argc, char** argv)
{
char* abc = "Hello";

char* abc2 = "Hello";

// the value (address) of abc is the same as abc2

return 0;
}



thanks in advance,
George

ovidiucucu
November 15th, 2007, 06:19 AM
May be but not obviously.
The standard states:

Whether all string literals are distinct (that is, are stored in nonoverlapping objects) is implementation-defined.

Zaccheus
November 15th, 2007, 10:08 AM
Here is my test program in Visual Studio 2005.
Visual Studio 2005 has a project option which specifies whether identical string literals are combined into one or stored as separate objects.

George2
November 15th, 2007, 10:10 AM
Hi ovidiucucu,


Where do you find the statements? Could you provide a URL please?

May be but not obviously.
The standard states:


regards,
George

George2
November 15th, 2007, 10:12 AM
Yes Zaccheus, I am using Visual Studio 2005. Could you let me know which option do you mean please?

Visual Studio 2005 has a project option which specifies whether identical string literals are combined into one or stored as separate objects.


regards,
George

Zaccheus
November 15th, 2007, 10:25 AM
http://msdn2.microsoft.com/en-us/library/s0s0asdt(VS.80).aspx

:)

George2
November 15th, 2007, 10:35 AM
Thanks Zaccheus!


http://msdn2.microsoft.com/en-us/library/s0s0asdt(VS.80).aspx

:)


regards,
George

ovidiucucu
November 15th, 2007, 02:03 PM
Hi ovidiucucu,


Where do you find the statements? Could you provide a URL please?




regards,
George
I quoted from "ISO/IEC 14882 - Programming languages — C++" standard and unfortunately I have not a free URL for that.
Anyhow, you are welcome!

George2
November 16th, 2007, 01:50 AM
Thanks ovidiucucu,


I quoted from "ISO/IEC 14882 - Programming languages — C++" standard and unfortunately I have not a free URL for that.
Anyhow, you are welcome!

I have got it.


regards,
George