digitalmars.D - implicit casts with dmd ver 1.0
- Peter Blicharski (8/8) Jan 19 2007 Hello.
- Dave (4/16) Jan 19 2007 This was due to a change right before v1.0.
- Johan Granberg (6/17) Jan 19 2007 The implicit cast from char[] to char* was deprecated shortly before 1.0...
- Frits van Bommel (9/14) Jan 19 2007 It was removed in version v0.177 at the request of an overwhelming
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
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
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 BlicharskiThe 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
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