September 24, 2004
"Thomas Kuehne" <eisvogel@users.sourceforge.net> wrote in message news:civjub$27rp$2@digitaldaemon.com...
> Ben Hinkle schrieb:
> > It would also be nice to say on the web page which platform the tests
were
> > run on.
> Yup, done
>
> > When I run foreach_13.d on win32 it passes just fine. Plus I'm not
> > sure one can change the values in string constants (ala C string
> > constants).
> > Try "dup"ing the string before changing it.
>
> I don't see any constant there.
>
> I thought the following snipplets had the same effect ...
>
> --A--
> char[2] array;
> array[0]='a';
> array[1]='b';
>
> --B--
> char[] array="ab";
>
> apparently  they behave differently - at least on linux ;)
>
> Rewritten in plain c and compiled with gcc-3.4 those two snipplets behaved alike.

What was your C code? When I write the C program:
int main() {
 char*str = "ab";
 str[1] = 't';
 return 0;
}
I get a seg-v. The reason is that the constant string "ab" is read-only.
See for example item 1.32 of http://www.faqs.org/faqs/C-faq/faq/

-Ben


September 24, 2004
Ben Hinkle schrieb:
> > --A--
> > char[2] array;
> > array[0]='a';
> > array[1]='b';
> >
> > --B--
> > char[] array="ab";
> >
> > apparently  they behave differently - at least on linux ;)
> >
> > Rewritten in plain c and compiled with gcc-3.4 those two snipplets
behaved
> > alike.
>
> What was your C code? When I write the C program:
> int main() {
>  char*str = "ab";
>  str[1] = 't';
>  return 0;
> }
> I get a seg-v. The reason is that the constant string "ab" is read-only.
> See for example item 1.32 of http://www.faqs.org/faqs/C-faq/faq/

I didn't use a pointer but an array:

--A.c--
#include <assert.h>

int main(){
     char str[1];
     str[0]='C';
     str[0]+=1;
     assert(str[0]=='D');
     return 0;
}

--B.c--
#include <assert.h>

int main(){
     char str[]="C";
     str[0]+=1;
     assert(str[0]=='D');
     return 0;
}


September 24, 2004
Thomas Kuehne wrote:

> Ben Hinkle schrieb:
>> > --A--
>> > char[2] array;
>> > array[0]='a';
>> > array[1]='b';
>> >
>> > --B--
>> > char[] array="ab";
>> >
>> > apparently  they behave differently - at least on linux ;)
>> >
>> > Rewritten in plain c and compiled with gcc-3.4 those two snipplets
> behaved
>> > alike.
>>
>> What was your C code? When I write the C program:
>> int main() {
>>  char*str = "ab";
>>  str[1] = 't';
>>  return 0;
>> }
>> I get a seg-v. The reason is that the constant string "ab" is read-only.
>> See for example item 1.32 of http://www.faqs.org/faqs/C-faq/faq/
> 
> I didn't use a pointer but an array:
> 
> --A.c--
> #include <assert.h>
> 
> int main(){
>      char str[1];
>      str[0]='C';
>      str[0]+=1;
>      assert(str[0]=='D');
>      return 0;
> }
> 
> --B.c--
> #include <assert.h>
> 
> int main(){
>      char str[]="C";
>      str[0]+=1;
>      assert(str[0]=='D');
>      return 0;
> }

Apparently (and I think this is ok) the D code
 char[] str = "C";
isn't like the C code
 char str[] = "C";
It is more like
 char* str = "C";
 int len = 1;

The FAQ I referenced has more info about the difference.
September 25, 2004
> Concerning adding & fixing:
> Tomorrow I am going to bring the cvs server online.
> Anonymous read access for everyone and write access on request.

Well ... a bit later and a subversion server instead of a cvs server .. but yeah it's finally online ;)

svn checkout svn://svn.kuehne.cn/dstress

For those not knowing what subversion is: http://subversion.tigris.org/

Thomas


1 2
Next ›   Last »