digitalmars.D.learn - copy char to char[]
- nix (27/27) Mar 17 2005 Hello,
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (10/23) Mar 17 2005 No, it's because string literals are read/write on
- nix (4/36) Mar 17 2005 Thanks a lot.
- uframer (2/39) Mar 18 2005
- Regan Heath (4/47) Mar 18 2005 Unfortunately not so weird if you use the M$ C/C++ compiler for Win32 an...
- Jan-Eric Duden (2/5) Jun 22 2005 Except in C++ you would declare it as a const char array....
- Regan Heath (6/11) Jun 22 2005 Unless you forgot to add that little word "const". Really the compiler
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.Except in C++ you would declare it as a const char array....
Jun 22 2005
On Wed, 22 Jun 2005 13:07:14 +0200, Jan-Eric Duden <jeduden whisset.com> wrote:Regan Heath wrote: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). ReganUnfortunately 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....
Jun 22 2005