digitalmars.D.bugs - array handling Linux<->Windows
- Thomas Kuehne (8/8) Sep 27 2004 The code below will result in a segment fault under Linux but runs on
- Ben Hinkle (6/15) Sep 27 2004 I don't think this is a bug - it's like the C (and C++) behavior for str...
- Stewart Gordon (6/10) Sep 27 2004 I'd been under the impression that initialising a char[] was supposed
- Dave (3/6) Sep 27 2004 Hear, hear!!
- Burton Radons (25/26) Sep 27 2004 Next you'll want undefined expressions to have consistent undefined
- Arcane Jill (5/9) Sep 27 2004 Hmmm. It's a shame we can't write:
- Regan Heath (8/19) Sep 27 2004 We can write that.. however the 'const' applies to the array reference,
- Sean Kelly (3/11) Sep 28 2004 Yup. The C++ syntax would be something like:
- Ben Hinkle (11/24) Sep 28 2004 I think you mean "char const* const str" or "const char* const str"
- Sean Kelly (9/34) Sep 28 2004 It is kind of odd that there's no way to use "const" correctly here. Wh...
- Thomas Kuehne (6/18) Sep 27 2004 To me it isn't a bug that the code runs/crashs.
- Ant (10/18) Sep 27 2004 http://www.digitalmars.com/d/dcompiler.html
- Thomas Kuehne (4/22) Sep 27 2004 Hrrr, I've been searching through the language definition stuff, but the...
The code below will result in a segment fault under Linux but runs on Windows. int main(){ char[] str="a1"; str[0]++; assert(str[0]=='b'); return 0; }
Sep 27 2004
Thomas Kuehne wrote:The code below will result in a segment fault under Linux but runs on Windows. int main(){ char[] str="a1"; str[0]++; assert(str[0]=='b'); return 0; }I don't think this is a bug - it's like the C (and C++) behavior for string literals. This came up on the main thread a few days ago. It should be mentioned in the doc if it isn't already. To get a modifyable string call dup. -Ben
Sep 27 2004
In article <cj90ft$a4o$1 digitaldaemon.com>, Ben Hinkle says... <snip>I don't think this is a bug - it's like the C (and C++) behavior for string literals. This came up on the main thread a few days ago. It should be mentioned in the doc if it isn't already. To get a modifyable string call dup.I'd been under the impression that initialising a char[] was supposed to create a modifyable copy of the initialisation data. But whatever the intended behaviour is, it ought to be portable. Stewart.
Sep 27 2004
Stewart Gordon wrote: [snip]But whatever the intended behaviour is, it ought to be portable. Stewart.Hear, hear!!
Sep 27 2004
Stewart Gordon wrote:But whatever the intended behaviour is, it ought to be portable.Next you'll want undefined expressions to have consistent undefined behaviour. :) The code doesn't work on Windows either anyway. void main () { char [] a = "foo"; char [] b = "foo"; a [0] = 'b'; printf ("%.*s %.*s\n", a, b); } This prints "boo boo". This appears to be a bug in DMD, because constant sections are definitely available and used in Windows: void main () { ubyte *foo = cast (ubyte *) &main; printf ("%p %d\n", *foo, foo); *foo = *foo; } This prints the address and data properly but Access Violates in the assignment, indicating that "main" is put in a read-only section. Walter, once you come back, can you explain why const data is not being put into constant sections on Windows? I remember discussing this but it was years ago.
Sep 27 2004
In article <cj90ft$a4o$1 digitaldaemon.com>, Ben Hinkle says...I don't think this is a bug - it's like the C (and C++) behavior for string literals. This came up on the main thread a few days ago. It should be mentioned in the doc if it isn't already. To get a modifyable string call dup.Hmmm. It's a shame we can't write: to get platform-neutral behavior, isn't it? Jill
Sep 27 2004
On Mon, 27 Sep 2004 13:28:17 +0000 (UTC), Arcane Jill <Arcane_member pathlink.com> wrote:In article <cj90ft$a4o$1 digitaldaemon.com>, Ben Hinkle says...We can write that.. however the 'const' applies to the array reference, not the data it refers to, AFAIK there is no way to apply const to the data it refers to. Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/I don't think this is a bug - it's like the C (and C++) behavior for string literals. This came up on the main thread a few days ago. It should be mentioned in the doc if it isn't already. To get a modifyable string call dup.Hmmm. It's a shame we can't write: to get platform-neutral behavior, isn't it?
Sep 27 2004
In article <opsez7nkdr5a2sq9 digitalmars.com>, Regan Heath says...Yup. The C++ syntax would be something like: char const[] const str;Hmmm. It's a shame we can't write: to get platform-neutral behavior, isn't it?We can write that.. however the 'const' applies to the array reference, not the data it refers to, AFAIK there is no way to apply const to the data it refers to.
Sep 28 2004
"Sean Kelly" <sean f4.ca> wrote in message news:cjc6oe$2mci$1 digitaldaemon.com...In article <opsez7nkdr5a2sq9 digitalmars.com>, Regan Heath says...I think you mean "char const* const str" or "const char* const str" In C++ omitting the length of the array (eg char[] str) just means to implicitly determine the length from the initializer (I thought). So char str[] = "foobar"; is the same as char str[7] = "foobar"; which is very different than char* str = "foobar"; -BenYup. The C++ syntax would be something like: char const[] const str;Hmmm. It's a shame we can't write: to get platform-neutral behavior, isn't it?We can write that.. however the 'const' applies to the array reference, not the data it refers to, AFAIK there is no way to apply const to the data it refers to.
Sep 28 2004
In article <cjc8s1$2nlu$1 digitaldaemon.com>, Ben Hinkle says..."Sean Kelly" <sean f4.ca> wrote in message news:cjc6oe$2mci$1 digitaldaemon.com...Well yeah, I was trying to create a D equivalent.In article <opsez7nkdr5a2sq9 digitalmars.com>, Regan Heath says...I think you mean "char const* const str" or "const char* const str"Yup. The C++ syntax would be something like: char const[] const str;Hmmm. It's a shame we can't write: to get platform-neutral behavior, isn't it?We can write that.. however the 'const' applies to the array reference, not the data it refers to, AFAIK there is no way to apply const to the data it refers to.In C++ omitting the length of the array (eg char[] str) just means to implicitly determine the length from the initializer (I thought). So char str[] = "foobar"; is the same as char str[7] = "foobar"; which is very different than char* str = "foobar";It is kind of odd that there's no way to use "const" correctly here. What happens if you do this? char[] val = "static"; val ~= 'a'; ie. What is required to trigger the COW mechanism? I'd test this myself but my PC is about to go off for re-imaging. Sean
Sep 28 2004
Ben Hinkle schrieb:To me it isn't a bug that the code runs/crashs. The problem is that it behaves different on different plattforms. Consider a module written on a Windows box that runs fine there but crashs when used on Linux. Now, pin-point me the problematic code ;) ThomasThe code below will result in a segment fault under Linux but runs on Windows. int main(){ char[] str="a1"; str[0]++; assert(str[0]=='b'); return 0; }I don't think this is a bug - it's like the C (and C++) behavior for string literals. This came up on the main thread a few days ago. It should be mentioned in the doc if it isn't already.
Sep 27 2004
In article <cj8uoq$63b$1 digitaldaemon.com>, Thomas Kuehne says...The code below will result in a segment fault under Linux but runs on Windows. int main(){ char[] str="a1"; str[0]++; assert(str[0]=='b'); return 0; }http://www.digitalmars.com/d/dcompiler.html " Differences from Win32 version * String literals are read-only. Attempting to write to them will cause a segment violation. * The configuration file is /etc/dmd.conf " I thik that's it Ant
Sep 27 2004
Ant schrieb:Hrrr, I've been searching through the language definition stuff, but there it is on the _compiler_ page! ThomasThe code below will result in a segment fault under Linux but runs on Windows. int main(){ char[] str="a1"; str[0]++; assert(str[0]=='b'); return 0; }http://www.digitalmars.com/d/dcompiler.html " Differences from Win32 version * String literals are read-only. Attempting to write to them will cause a segment violation. * The configuration file is /etc/dmd.conf " I thik that's it Ant
Sep 27 2004