Thank you all.
Regards,
Santosh
Regards,
Santosh
On Wed, Aug 13, 2008 at 12:36 PM, Rene Herman <rene.herman@xxxxxxxxxxxx> wrote:
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.