The more interesting question
Alex Rønne Petersen
alex at lycus.org
Wed May 16 13:19:36 PDT 2012
On 16-05-2012 22:00, deadalnix wrote:
> Le 16/05/2012 12:10, Timon Gehr a écrit :
>> On 05/16/2012 12:29 AM, deadalnix wrote:
>>> Le 15/05/2012 20:34, Alex Rønne Petersen a écrit :
>>>> Besides, this is probably not going to change anyway. We're focusing on
>>>> stabilizing the language, not changing it.
>>>>
>>>
>>> This always have been a design mistake to auto cast array in pointers.
>>> This is silent fallback to usafe world, and what we want to avoid.
>>>
>>
>> Getting a pointer to the beginning of a zero-terminated string literal
>> is perfectly safe.
>>
>>> This has no benefit because using .ptr isn't really complex and make the
>>> transition obvious.
>>>
>>> This has been raised many time in the past as being an issue, and it fit
>>> nicely here.
>>>
>>
>> This is a compile time error:
>>
>> int[] arr;
>> int* p=arr;
>>
>> What exactly are you asking for?
>>
>
> void foo(const(char)*);
>
> foo("bar");
>
> isn't .
And shouldn't be. Working with C APIs or just working on druntime would
be a nightmare.
>
>>> Having \0 terminated string in D were it has no usage is quite dumb.
>>
>> What you don't seem to get is that it actually has usage.
>
> I understand that. I want to propose something more subtle.
>
> Array in D are already typed according to what the are assigned. int[]
> foo = [1, 2] and immutable(int)[] = [1, 2] are both possible). Isn't it
> possible to \0 terminate string chen they are used as char* and not when
> they are used as array ?
Theoretically, yes, practically, not really.
void myLog(string msg)
{
printf(msg);
}
--
Alex Rønne Petersen
alex at lycus.org
http://lycus.org
More information about the Digitalmars-d
mailing list