September 28, 2004
In article <opsez7nkdr5a2sq9@digitalmars.com>, Regan Heath says...
>
>> Hmmm. It's a shame we can't write:
>>
>> #    const char[] str="a1";
>>
>> 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.

Yup.  The C++ syntax would be something like:

char const[] const str;


September 28, 2004
"Sean Kelly" <sean@f4.ca> wrote in message news:cjc6oe$2mci$1@digitaldaemon.com...
> In article <opsez7nkdr5a2sq9@digitalmars.com>, Regan Heath says...
> >
> >> Hmmm. It's a shame we can't write:
> >>
> >> #    const char[] str="a1";
> >>
> >> 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.
>
> Yup.  The C++ syntax would be something like:
>
> char const[] const str;
>
>

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";

-Ben


September 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...
>> In article <opsez7nkdr5a2sq9@digitalmars.com>, Regan Heath says...
>> >
>> >> Hmmm. It's a shame we can't write:
>> >>
>> >> #    const char[] str="a1";
>> >>
>> >> 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.
>>
>> Yup.  The C++ syntax would be something like:
>>
>> char const[] const str;
>
>I think you mean "char const* const str" or "const char* const str"

Well yeah, I was trying to create a D equivalent.

>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


1 2
Next ›   Last »