Re: A simple query about memory mgmt

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

 



On 13-08-08 08:40, Peter Teoh wrote:

Not to annoy you further, but this is actually a fairly important point:

But if it is written as such:

#define NAME "santosh"

int main()
{
    char *p_name = NAME;
    char *q_name = NAME;
    if (p_name == q_name)
         printf("Hello, World\n");
    return 0;
}

I would not consider it an optimization.   Because, the string NAME
are allocated off from the static heap area.   And by nature #define
tell the compiler to inline duplicate the following contents - eg,
codes/functions, but for constant pointer values it is not.

#define does not allocate anything nor does it tell the compiler anything. Anything starting with a # in C is not handled by the compiler, but by the C pre-processor (man cpp).

Now, since only fairly recently, GCC's C pre-processor and C compiler are in fact integrated into a single binary but the conceptual split is still very much in place. The C pre-processor should conceptually be viewed as a general textfile processing tool and no more.

If _any_ different output would result from this and your first one:

#define NAME "santosh"
#define NAME1 "santosh"

int main()
{
    char *p_name = NAME;
    char *q_name = NAME1;
    if (p_name == q_name)
         printf("Hello, World\n");
    return 0;
}

you'd have found a violent bug in the tool chain. Consequently, if you'd expect any such difference, you'd have found a violent bug in your thinking ;-)

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