| Felipe Sateler wrote:
> With gcc, there are a lot of warnings in the csound code about the
> conversion to char* from a string literal (eg: char *foo = "something"). I'm
> wondering if that warning is correct:
Yes, it is.
Strings literals like "something" are read-only strings are allocated in
read-only memory. Modifying string literals will result in a segmentation
fault for all versions of gcc >= 3.0.
If you want a modifiable string use:
char foo [] = "something" ;
> either the string is modifiable and
> should not be set to a constant, or the string is not modifiable and should
> be marked as such.
The later.
> Note that while the following code might work, it is mere luck:
>
> char* foo="hello";
> foo[2]='z';
On Linux, with recent versions of gcc it segfaults.
Erik
--
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
I have found that good programmers either do not make the kind
of mistakes that Ada can prevent, or insert enough checks that
they catch those mistakes about as efficiently as an Ada
environment can. At that point, the use of Ada gives no further
productivity advantage.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net |