Thread overview
copy char to char[]
Mar 17, 2005
nix
Mar 18, 2005
nix
Mar 18, 2005
uframer
Mar 19, 2005
Regan Heath
Jun 22, 2005
Jan-Eric Duden
Jun 22, 2005
Regan Heath
March 17, 2005
Hello,

this Programm run fine under Windows:

import std.stdio; int main() {

char[] str = "123456"; str[0] ='A'; writefln("str = %s",str); return 0; }

but didn't run under linux. (Speicherzugriffsfehler) Can this be a problem from my character set?

LANG=de_DE.UTF-8 LC_CTYPE="de_DE.UTF-8" LC_NUMERIC="de_DE.UTF-8" LC_TIME="de_DE.UTF-8" LC_COLLATE="de_DE.UTF-8" LC_MONETARY="de_DE.UTF-8" LC_MESSAGES="de_DE.UTF-8" LC_PAPER="de_DE.UTF-8" LC_NAME="de_DE.UTF-8" LC_ADDRESS="de_DE.UTF-8" LC_TELEPHONE="de_DE.UTF-8" LC_MEASUREMENT="de_DE.UTF-8" LC_IDENTIFICATION="de_DE.UTF-8" LC_ALL=de_DE.UTF-8

My system in Debian testing. dmd 0.118




March 17, 2005
nix wrote:

> this Programm run fine under Windows: 
> 
> import std.stdio; int main() { 
> 
> char[] str = "123456"; str[0] ='A'; writefln("str = %s",str); return 0; } 
> 
> but didn't run under linux. (Speicherzugriffsfehler) Can this be a problem from my character set? 

No, it's because string literals are read/write on
Windows and read-only on Linux and other platforms...

It's a known "platform-specific behaviour" of D.
(It is solved in C/C++ by using "const char *")


Short consequence, use: char[] str = "123456".dup;
That string will be read-write on every D platform...

--anders


PS. German "Speicherzugriffsfehler" is known as
    segmentation fault (or segfault) in English...
March 18, 2005
Thanks a lot. What a trap. :-)

In article <d1c62o$1438$1@digitaldaemon.com>, =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...
> 
>nix wrote:
> 
>> this Programm run fine under Windows:
>> 
>> import std.stdio;
>> int main() {
>> 
>> char[] str = "123456";
>> str[0] ='A';
>> writefln("str = %s",str);
>> return 0;
>> }
>> 
>> but didn't run under linux. (Speicherzugriffsfehler)
>> Can this be a problem from my character set?
> 
>No, it's because string literals are read/write on Windows and read-only on Linux and other platforms...
> 
>It's a known "platform-specific behaviour" of D. (It is solved in C/C++ by using "const char *")
> 
> 
>Short consequence, use: char[] str = "123456".dup; That string will be read-write on every D platform...
> 
>--anders
> 
> 
>PS. German "Speicherzugriffsfehler" is known as
>     segmentation fault (or segfault) in English...



March 18, 2005
What a weired behaviour!
"nix" <nix_member@pathlink.com> дÈëÏûÏ¢ÐÂÎÅ:d1e15c$858$1@digitaldaemon.com...
> Thanks a lot.
> What a trap. :-)
>
> In article <d1c62o$1438$1@digitaldaemon.com>, =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...
>>
>>nix wrote:
>>
>>> this Programm run fine under Windows:
>>>
>>> import std.stdio;
>>> int main() {
>>>
>>> char[] str = "123456";
>>> str[0] ='A';
>>> writefln("str = %s",str);
>>> return 0;
>>> }
>>>
>>> but didn't run under linux. (Speicherzugriffsfehler)
>>> Can this be a problem from my character set?
>>
>>No, it's because string literals are read/write on
>>Windows and read-only on Linux and other platforms...
>>
>>It's a known "platform-specific behaviour" of D.
>>(It is solved in C/C++ by using "const char *")
>>
>>
>>Short consequence, use: char[] str = "123456".dup;
>>That string will be read-write on every D platform...
>>
>>--anders
>>
>>
>>PS. German "Speicherzugriffsfehler" is known as
>>     segmentation fault (or segfault) in English...
>
>
> 


March 19, 2005
Unfortunately not so weird if you use the M$ C/C++ compiler for Win32 and cc/gcc for Unix.
The exact same thing occurs.

On Fri, 18 Mar 2005 21:45:20 +0800, uframer <uframer@sina100.com.cn> wrote:
> What a weired behaviour!
> "nix" <nix_member@pathlink.com> дÈëÏûÏ¢ÐÂÎÅ:d1e15c$858$1@digitaldaemon.com...
>> Thanks a lot.
>> What a trap. :-)
>>
>> In article <d1c62o$1438$1@digitaldaemon.com>,
>> =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...
>>>
>>> nix wrote:
>>>
>>>> this Programm run fine under Windows:
>>>>
>>>> import std.stdio;
>>>> int main() {
>>>>
>>>> char[] str = "123456";
>>>> str[0] ='A';
>>>> writefln("str = %s",str);
>>>> return 0;
>>>> }
>>>>
>>>> but didn't run under linux. (Speicherzugriffsfehler)
>>>> Can this be a problem from my character set?
>>>
>>> No, it's because string literals are read/write on
>>> Windows and read-only on Linux and other platforms...
>>>
>>> It's a known "platform-specific behaviour" of D.
>>> (It is solved in C/C++ by using "const char *")
>>>
>>>
>>> Short consequence, use: char[] str = "123456".dup;
>>> That string will be read-write on every D platform...
>>>
>>> --anders
>>>
>>>
>>> PS. German "Speicherzugriffsfehler" is known as
>>>     segmentation fault (or segfault) in English...
>>
>>
>>
>
>

June 22, 2005
Regan Heath wrote:
> Unfortunately not so weird if you use the M$ C/C++ compiler for Win32 and  cc/gcc for Unix.
> The exact same thing occurs.
Except in C++ you would declare it as a const char array....
June 22, 2005
On Wed, 22 Jun 2005 13:07:14 +0200, Jan-Eric Duden <jeduden@whisset.com> wrote:
> Regan Heath wrote:
>> Unfortunately not so weird if you use the M$ C/C++ compiler for Win32 and  cc/gcc for Unix.
>> The exact same thing occurs.
> Except in C++ you would declare it as a const char array....

Unless you forgot to add that little word "const". Really the compiler knows it's const without our telling it, it put it in read only memory after all (if only on linux).

Regan