September 16, 2003
> >
> > while I like having the ability to pass a Derived[] as a Base[]
> > simply disallowing inout does not solve the problems of ending up with
> > an instance of Base in your array (or worse).
> > cast(X[])ar should check all elements of ar;
> > I've not used two threads but is I had then its easy to see a sitation
> > where one thread sees an array as a B[] (or worse Object[]) the other
> > sees the same range as D[], and chaos may follow shortly after
>
> I know about that gaping hole in type safety, but I don't see a fix for
it.
> It happens in C++ as well.
>
>
>

It is relatively easy to fix if the conversion is restricted to argument
with the proper type (that is in parameter --- in should apply to
the whole array).

I think that we should make it safe only if no casting is used...
(similar to C++).

Speaking of cast, I think that we should have more than one cast operator so that we can be more explicit on what we want to allows as conversion...

Casting to Derived[] an object of type Base[] should check
that the array was an array of Derived...Casting from
Derived[] to Base[] should require a cast except when
a modifier say that the array is in (or const if it was
supported --- another subject!!!)


September 16, 2003
In article <bk5l19$p7k$1@digitaldaemon.com>, Walter says...
>
>I know about that gaping hole in type safety, but I don't see a fix for it. It happens in C++ as well.
>

Please read Eiffel, also the multiple inheritance (MI) solution in Eiffel is
worth study.



September 16, 2003
Walter wrote:
> "Mike Wynn" <mike@l8night.co.uk> wrote in message
> news:bk5hf9$i90$1@digitaldaemon.com...
> 
>>Walter wrote:
>>
>>>A number of bugs fixed.
>>>
>>>http://www.digitalmars.com/d/changelog.html
>>>
>>
>>how do I create wchar strings now ?
>>
>>(file wchartest.d is just the line)
>>wchar[] foo( wchar[] msg ) { return msg ~ "foo"; }
>>
>>dmd -c wchartest.d
>>reports
>>
>>wchartest.d(1): incompatible types for ((msg) ~ ("foo")): 'wchar[]' and
>>'char[]'
> 
> 
> I should fix that. In the meantime, you can rewrite "foo" as
> cast(wchar[])"foo", or make
>     wchar[] foo = "foo";
>     return msg ~ foo;
> 

how safe is cast(wchar[])"...." because casting char[]<->wchar[]

as in ...

import c.stdio;

void showstrw( wchar[] tmp ) {
	printf( "len:%d ", tmp.length );
	for( int i = 0; i < tmp.length; i++ ) {
		printf("'%c'(%d) ", cast(char)tmp[i], cast(int)tmp[i] );
	}
}
void showstra( char[] tmp ) {
	printf( "len:%d ", tmp.length );
	for( int i = 0; i < tmp.length; i++ ) {
		printf("'%c'(%d) ", tmp[i], cast(int)tmp[i] );
	}
}

void process( char[] oca, wchar[] owa ) {
	printf( "\n wchar array as wchars    : " ); showstrw( owa );
	printf( "\n wchar array cast(char[]) : " ); showstra( cast(char[])owa );
	printf( "\n\n char array as chars      : " ); showstra( oca );
	printf( "\n char array cast(wchar[]) : " ); showstrw( cast(wchar[])oca );
	printf( "\n\n" );
}

int main(char[][] args ) {
	wchar[] owa = "abcd";
	char[]  oca = "abcd";
	process( oca.dup, owa.dup );
	return 0;
}

outputs
 wchar array as wchars    : len:4 'a'(97) 'b'(98) 'c'(99) 'd'(100)
 wchar array cast(char[]) : len:8 'a'(97) ''(0) 'b'(98) ''(0) 'c'(99) ''(0) 'd'(100) ''(0)

 char array as chars      : len:4 'a'(97) 'b'(98) 'c'(99) 'd'(100)
 char array cast(wchar[]) : len:2 'a'(25185) 'c'(25699)

(linux dmd 0.72)

September 16, 2003
In article <bk60t4$223l$1@digitaldaemon.com>, nobody@yahoo.com says...
>
>In article <bk5l19$p7k$1@digitaldaemon.com>, Walter says...
>>
>>I know about that gaping hole in type safety, but I don't see a fix for it. It happens in C++ as well.
>>
>
>Please read Eiffel, also the multiple inheritance (MI) solution in Eiffel is
>worth study.
>

P.S.  It's called type conformance rules.  Try to google "eiffel type conformance rules":

http://www.pi.informatik.tu-darmstadt.de/inf1/eiff-ref/chap13.htm



September 16, 2003
"Mike Wynn" <mike@l8night.co.uk> wrote in message news:bk611g$22fm$1@digitaldaemon.com...
> Walter wrote:
> > "Mike Wynn" <mike@l8night.co.uk> wrote in message news:bk5hf9$i90$1@digitaldaemon.com...
> >
> >>Walter wrote:
> >>
> >>>A number of bugs fixed.
> >>>
> >>>http://www.digitalmars.com/d/changelog.html
> >>>
> >>
> >>how do I create wchar strings now ?
> >>
> >>(file wchartest.d is just the line)
> >>wchar[] foo( wchar[] msg ) { return msg ~ "foo"; }
> >>
> >>dmd -c wchartest.d
> >>reports
> >>
> >>wchartest.d(1): incompatible types for ((msg) ~ ("foo")): 'wchar[]' and
> >>'char[]'
> >
> >
> > I should fix that. In the meantime, you can rewrite "foo" as
> > cast(wchar[])"foo", or make
> >     wchar[] foo = "foo";
> >     return msg ~ foo;
> >
>
> how safe is cast(wchar[])"...." because casting char[]<->wchar[]

Casting a "string" is handled specially by the compiler and it will do the UTF-8=>UTF-16 conversion on the literal.


September 16, 2003
<nobody@yahoo.com> wrote in message news:bk60t4$223l$1@digitaldaemon.com...
> In article <bk5l19$p7k$1@digitaldaemon.com>, Walter says...
> >I know about that gaping hole in type safety, but I don't see a fix for
it.
> >It happens in C++ as well.
> Please read Eiffel, also the multiple inheritance (MI) solution in Eiffel
is
> worth study.

Would you like to summarize it here for the newsgroup readers?


September 16, 2003
In article <bk62pb$26ig$3@digitaldaemon.com>, Walter says...
>
>
><nobody@yahoo.com> wrote in message news:bk60t4$223l$1@digitaldaemon.com...
>> In article <bk5l19$p7k$1@digitaldaemon.com>, Walter says...
>> >I know about that gaping hole in type safety, but I don't see a fix for
>it.
>> >It happens in C++ as well.
>> Please read Eiffel, also the multiple inheritance (MI) solution in Eiffel
>is
>> worth study.
>
>Would you like to summarize it here for the newsgroup readers?


For type conformance:

http://www.pi.informatik.tu-darmstadt.de/inf1/eiff-ref/chap13.htm

A quick summary (note, generic ~= template in C++/D):

Let T and V be two types. V conforms to T if and only if one of the following holds:

1. V and T are identical.
2. V conforms directly to T.
3. V is NONE and T is a reference type.
4. V is B [Y1,... Yn] for some generic class B, T is B [X1,... Xn], and every
one of the Yi conforms (recursively) to the corresponding Xi.
5. T is a reference type and, for some type U, V conforms to U and U conforms
(recursively) to T.


For multiple inheritance (MI):

http://www.pi.informatik.tu-darmstadt.de/inf1/eiff-ref/chap10.htm http://www.pi.informatik.tu-darmstadt.de/inf1/eiff-ref/chap11.htm http://www.pi.informatik.tu-darmstadt.de/inf1/eiff-ref/chap12.htm

Inheritance ::=
inherit Parent_list

Parent_list ::=
{Parent Separator ...}

Parent ::=
Restricted_class_type [Feature_adaptation]

Feature_adaptation ::=
[Rename]
[New_exports]
[Undefine]
[Redefine]
[Select]
end


September 16, 2003
That code works here using 0.72 , windows 2000 advanced, dmc8.36

>switch to name

Charles

"Mike Wynn" <mike@l8night.co.uk> wrote in message news:bk5t54$1njn$1@digitaldaemon.com...
> Walter wrote:
> > A number of bugs fixed.
> >
> > http://www.digitalmars.com/d/changelog.html
> >
> >
> >
> there seems to be a problem with wchar switchs I have some code that reads from a file (bytes) and casts to wchar ... though that was the problem, has taken me a while to get a 10 line prog to repro this ... but here it is with internal strings.
>
> ----------------------------------
>
> import c.stdio;
>
> wchar[] getName() {
> return "name";
> }
>
> int main(char[][] args ) {
> wchar[] tmp = getName();
> switch( tmp ) {
> case "name":
> printf("switch to name\n");
> break;
> case "afoo": printf("switch to afoo\n"); break;
> default:
> printf("switch to default(not afoo or name)\n");
> printf("tmp[0..%d]:\n", tmp.length);
> for( int i = 0; i < tmp.length; i++ ) {
> printf("tmp[%d] = '%c'(%d)\n", i, cast(char)tmp[i], cast(int)tmp[i] );
> }
> break;
> }
> return 0;
> }
> ---------------------------
> switch to default(not afoo or name)
> tmp[0..4]:
> tmp[0] = 'n'(110)
> tmp[1] = 'a'(97)
> tmp[2] = 'm'(109)
> tmp[3] = 'e'(101)
>


September 16, 2003
Thanks!


September 16, 2003
Charles Sanders wrote:
> That code works here using 0.72 , windows 2000 advanced, dmc8.36
> 

sorry forgot the version/os - linux(RH9 gcc 3.2.2) dmd 0.71 and 0.72

small changes and it works like adding ":" ~ val and ":..."
only seems to be an issue with 4 char values ...
> 
>>switch to name
> 
> 
> Charles
> 
> "Mike Wynn" <mike@l8night.co.uk> wrote in message
> news:bk5t54$1njn$1@digitaldaemon.com...
> 
>>Walter wrote:
>>
>>>A number of bugs fixed.
>>>
>>>http://www.digitalmars.com/d/changelog.html
>>>
>>>
>>>
>>
>>there seems to be a problem with wchar switchs I have some code that
>>reads from a file (bytes) and casts to wchar ... though that was the
>>problem, has taken me a while to get a 10 line prog to repro this ...
>>but here it is with internal strings.
>>
>>----------------------------------
>>
>>import c.stdio;
>>
>>wchar[] getName() {
>>return "name";
>>}
>>
>>int main(char[][] args ) {
>>wchar[] tmp = getName();
>>switch( tmp ) {
>>case "name":
>>printf("switch to name\n");
>>break;
>>case "afoo": printf("switch to afoo\n"); break;
>>default:
>>printf("switch to default(not afoo or name)\n");
>>printf("tmp[0..%d]:\n", tmp.length);
>>for( int i = 0; i < tmp.length; i++ ) {
>>printf("tmp[%d] = '%c'(%d)\n", i, cast(char)tmp[i], cast(int)tmp[i] );
>>}
>>break;
>>}
>>return 0;
>>}
>>---------------------------
>>switch to default(not afoo or name)
>>tmp[0..4]:
>>tmp[0] = 'n'(110)
>>tmp[1] = 'a'(97)
>>tmp[2] = 'm'(109)
>>tmp[3] = 'e'(101)
>>
> 
> 
>