Google
  Web www.spinics.net

Re: A simple query about memory mgmt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On 13-08-08 02:57, Peter Teoh wrote:

But since u have assigned it to the same address of NAME, it will always print HELLO world. So the whole thing has nothing got to do with optimization (gcc -O0 to disable it, which is also default).

Can y'all please just listen to Johannes? It definitely does. We have:

int main()
{
    char *p_name = "santosh";
    char *q_name = "santosh";

It is unspecified whether or not the compiler will allocate one or two copies of the character sequence "santosh" and therefore whether or not p_name != q_name;

Just replace it by

int main()
{
    char *p_name = "santosh";
    char *q_name = "peter";

to understand that allocating it just once is an optimization.

Rene.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Newbies FAQ]     [Kernel List]     [Site Home]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Rubini]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Networking]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]     [DDR & Rambus]     [UNIX Filesystems]     [Linux Resources]

Add to Google Powered by Linux