digitalmars.D.learn - copy char to char[]
- nix <nix_member pathlink.com> Mar 17 2005
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> Mar 17 2005
- nix <nix_member pathlink.com> Mar 17 2005
- "uframer" <uframer sina100.com.cn> Mar 18 2005
- "Regan Heath" <regan netwin.co.nz> Mar 18 2005
- Jan-Eric Duden <jeduden whisset.com> Jun 22 2005
- "Regan Heath" <regan netwin.co.nz> Jun 22 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
Mar 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...
Mar 17 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...
Mar 17 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...
Mar 18 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...
Mar 18 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.
Jun 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.
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
Jun 22 2005








"Regan Heath" <regan netwin.co.nz>