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


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux