Thomas Hruska a écrit :
> 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).
>
>   

I don't know much C,
But can you clarified this : "both are identical" ?
I am not sure to understand.

I don't have intel icc compiler to see assembly generated by both code But it 
could be interested to see what will be generated by (two initialization with 
the same literal c-string)

char* q = "abcdef"; // could be (as with aCC) a warning for C++
char* p = "abcdef";

And 

char q[] = "abcdef";
char p[] = "abcdef";

David


Reply via email to