why is string not implicit convertable to const(char*) ?

2012-06-29 Thread mta`chrono
does anyone know why string not implicit convertable to const(char*) ? --- import core.sys.posix.unistd; void main() { // ok unlink("foo.txt"); // failed string file = "bar.txt"; unlink(file); } test.d(10): Error: function core.sys.posix.unistd.unlink

Re: why is string not implicit convertable to const(char*) ?

2012-06-29 Thread Jonathan M Davis
On Saturday, June 30, 2012 02:12:22 mta`chrono wrote: > does anyone know why string not implicit convertable to const(char*) ? > > --- > import core.sys.posix.unistd; > > void main() > { > // ok > unlink("foo.txt"); > > // failed > string file = "bar.txt"; >

Re: why is string not implicit convertable to const(char*) ?

2012-07-02 Thread mta`chrono
Your answers are remarkable elaborated. Thanks for your great effort, Jonathan!! ;-)

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread dcoder
On Saturday, 30 June 2012 at 00:27:46 UTC, Jonathan M Davis wrote: On Saturday, June 30, 2012 02:12:22 mta`chrono wrote: does anyone know why string not implicit convertable to const(char*) ? --- import core.sys.posix.unistd; void main() { // ok unlink("foo.txt");

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Timon Gehr
On 07/05/2012 09:32 PM, dcoder wrote: Thanks for the thorough explanation, but it begs the question why not make strings be array of chars that have \0 at the end of it? Because that is inefficient. It disables string slicing and is completely redundant. BTW: String literals are guaranteed

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Jonathan M Davis
On Thursday, July 05, 2012 21:32:11 dcoder wrote: > Thanks for the thorough explanation, but it begs the question why > not make strings be array of chars that have \0 at the end of it? > Since, lots of D programmers were/are probably C/C++ > programmers, why should D be different here? Wouldn't

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Wouter Verhelst
Jonathan M Davis writes: > On Thursday, July 05, 2012 21:32:11 dcoder wrote: >> Thanks for the thorough explanation, but it begs the question why >> not make strings be array of chars that have \0 at the end of it? >> Since, lots of D programmers were/are probably C/C++ >> programmers, why shou

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Timon Gehr
On 07/06/2012 02:57 AM, Wouter Verhelst wrote: Jonathan M Davis writes: On Thursday, July 05, 2012 21:32:11 dcoder wrote: Thanks for the thorough explanation, but it begs the question why not make strings be array of chars that have \0 at the end of it? Since, lots of D programmers were/ar

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Jonathan M Davis
On Thursday, July 05, 2012 18:57:05 Wouter Verhelst wrote: > Jonathan M Davis writes: > > On Thursday, July 05, 2012 21:32:11 dcoder wrote: > >> Thanks for the thorough explanation, but it begs the question why > >> not make strings be array of chars that have \0 at the end of it? > >> > >> Sin

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Wouter Verhelst
Timon Gehr writes: > On 07/06/2012 02:57 AM, Wouter Verhelst wrote: >> To be fair, there are a _few_ areas in which zero-terminated strings may >> possibly outperform zero-terminated strings (appending data in the case >> where you know the memory block is large enough, for instance). > > It is i

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Wouter Verhelst
Jonathan M Davis writes: > On Thursday, July 05, 2012 18:57:05 Wouter Verhelst wrote: >> To be fair, there are a _few_ areas in which zero-terminated strings may >> possibly outperform zero-terminated strings (appending data in the case >> where you know the memory block is large enough, for inst

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Jonathan M Davis
On Thursday, July 05, 2012 19:59:26 Wouter Verhelst wrote: > Well, really, strings in C are just a special case of arrays (as is true > in D as well), and arrays in C are just a special case of pointers > (which isn't true in D). That means the language is fairly compact, > which also means the com

Re: why is string not implicit convertable to const(char*) ?

2012-07-05 Thread Timon Gehr
On 07/06/2012 03:40 AM, Wouter Verhelst wrote: Timon Gehr writes: On 07/06/2012 02:57 AM, Wouter Verhelst wrote: To be fair, there are a _few_ areas in which zero-terminated strings may possibly outperform zero-terminated strings (appending data in the case where you know the memory block is

Re: why is string not implicit convertable to const(char*) ?

2012-07-06 Thread dcoder
Thanks for the lengthy threaded explanations. I just use the language to write applications, I have no idea of the challenges that you must face to implement/design a language. Hence the stupid questions. :) Anyways, fascinating stuff.

Re: why is string not implicit convertable to const(char*) ?

2012-07-06 Thread Wouter Verhelst
Timon Gehr writes: > This incurs the cost of determining the original string's length, There are ways to know the original string's length without having to calculate it. E.g., if you do a read() with some length and you don't get an error message indicating that there aren't as many characters a

Re: why is string not implicit convertable to const(char*) ?

2012-07-06 Thread Jonathan M Davis
On Friday, July 06, 2012 12:56:36 Wouter Verhelst wrote: > However, I also happen > to think that saying "zero-terminated strings were a horrendous design > decision" is a bit short-sighted. Well, then we're going to have to agree to disagree on that one. While some design decisions may have made

Re: why is string not implicit convertable to const(char*) ?

2012-07-07 Thread akaz
Well, then we're going to have to agree to disagree on that one. While some design decisions may have made more sense at the time they were made or the ultimate pros and cons may not have been clear at the time, I think that zero- terminated strings are one of the design decisions which was tru