How to use sprintf
Peter Alexander
peter.alexander.au at gmail.com
Tue Apr 26 07:39:34 PDT 2011
On 26/04/11 2:11 PM, Alexander wrote:
> On 26.04.2011 13:59, Steven Schveighoffer wrote:
>
>> Currently, casting an array to a pointer is a special case of casting in the compiler, which basically returns arr.ptr. However, that functionality is already available via arr.ptr.
>
> To me (coming from C/C++) it looks more natural to cast instead if using arr.ptr. After all, array is a pointer (=reference), and arrays are not structs (=values), so I see no reason to disallow this, to be honest.
>
> And, indeed, once disallowed, it will break a lot of existing code...
>
> /Alexander
This is wrong on two levels:
1. In D, an array is not a pointer. It is a struct with two members: a
length and a pointer. It is not the same as C or C++ array.
2. Even in C++, an array is not a pointer. The type of an array in C++
is T[N] whereas a pointer is T*. The only reasons you can pass an array
into a function that accepts a pointer is because of an implicit
conversion. Arrays are implemented as pointers, but they are not the
same type.
More information about the Digitalmars-d
mailing list