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:#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).
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.
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: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 ;-)
#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;
}
Rene.
[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]
![]() |
![]() |