www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - implicit casts with dmd ver 1.0

reply Peter Blicharski <mahatma ghandi.de> writes:
Hello.

I'm having trouble with the sample code shipped with dmd Ver 1.0
During compilation i encounter implicit cast errors (file dhry.d)
By the way, the the dfl window library code is full of these error, too.
Isn't the dmd compiler supposed to make a cast from char[] to char*
without error? Or is it needed to always make an explicit cast?

Best regards

Peter Blicharski
Jan 19 2007
next sibling parent Dave <Dave_member pathlink.com> writes:
Peter Blicharski wrote:
 Hello.
 
 I'm having trouble with the sample code shipped with dmd Ver 1.0
 During compilation i encounter implicit cast errors (file dhry.d)
 By the way, the the dfl window library code is full of these error, too.
 Isn't the dmd compiler supposed to make a cast from char[] to char*
 without error? Or is it needed to always make an explicit cast?
 
This was due to a change right before v1.0. You can use arr.ptr to avoid the explicit cast. If it has to be null terminated (for example to pass into an extern (C) function) you can use std.string.toStringz().
 Best regards
 
 Peter Blicharski
 
Jan 19 2007
prev sibling next sibling parent Johan Granberg <lijat.meREM OVE.gmail.com> writes:
Peter Blicharski wrote:

 Hello.
 
 I'm having trouble with the sample code shipped with dmd Ver 1.0
 During compilation i encounter implicit cast errors (file dhry.d)
 By the way, the the dfl window library code is full of these error, too.
 Isn't the dmd compiler supposed to make a cast from char[] to char*
 without error? Or is it needed to always make an explicit cast?
 
 Best regards
 
 Peter Blicharski
The implicit cast from char[] to char* was deprecated shortly before 1.0. Use this instead but be carefull as there is no guarantee that a is nullterminated (if it is a slice it wont). char[] a="asdsdfs"; char* b=a.ptr;
Jan 19 2007
prev sibling parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Peter Blicharski wrote:
 I'm having trouble with the sample code shipped with dmd Ver 1.0
 During compilation i encounter implicit cast errors (file dhry.d)
 By the way, the the dfl window library code is full of these error, too.
 Isn't the dmd compiler supposed to make a cast from char[] to char*
 without error? Or is it needed to always make an explicit cast?
It was removed in version v0.177 at the request of an overwhelming majority of people responding to a proposal to do so (IIRC). It's just too bug-prone, especially when interacting with C APIs. (In general, D strings aren't null-terminated) It looks like the sample wasn't updated. If you're sure you want this conversion to occur, you can use arr.ptr to get the pointer. If you want to ensure null-termination you are encouraged to use std.string.toStringz though.
Jan 19 2007