kou ksk wrote:
>> Why are you bothering to even manipulate the string? On many compilers, 
>> the code will "crash" (GPF) because you will be attempting to modify 
>> read-only memory. 
> 
> Thomas,
> I am afraid that this is not at all true for this code and in widely used 
> compilers including 
> gcc, borland. What you are saying is right for :
> 
> char *p="hello";
> p[1]='2';  //this will crash on gcc
> 
> but, as in Anurag's code,
> char p[]="hello";
> p[1]='2'; //this will not at all crash !!!!
> 
> -kou.

Tempting fate is always a bad idea.  From my perspective, both are 
identical and interchangeable.  An overzealous optimizing compiler (e.g. 
Intel*) may think the same way.

* Intel's optimizing compiler suite couldn't/can't be used, for 
instance, to compile the Linux kernel.  (Or at least it used to not be 
able to because it was overzealous in its optimizations - at least that 
was the explanation I received).

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to