Disallow arrays as pointers

deadalnix deadalnix at gmail.com
Wed Nov 2 14:13:22 PDT 2011


Le 31/10/2011 21:35, Timon Gehr a écrit :
> On 10/31/2011 02:49 AM, bearophile wrote:
>> Timon Gehr:
>>
>>> A lot of C's carefully designed syntactic elegance is
>>> lost when going from pointers/iterators to arrays and ranges.
>>
>> I think that a large part of that C syntactic elegance is an illusion.
>> From my experience, I want my code to look very simple to read and
>> clean every time this is possible. I want it to be easy to port to
>> other languages, because I have do it often enough. C code that uses
>> lot of pointers is often bug-prone, messy and hard to safely translate
>> to other languages.
>>
>> There are situation where pointers are necessary or are better than
>> the alternatives, or they give the needed flexibility, so I prefer a
>> language with pointers, but in a well designed language those
>> situations are not common, and I think raw pointers should be avoided
>> when they are not needed. I have debugged enough C code to be rather
>> sure of this. Good luck with your pointers.
>>
>
> I rarely use pointers in D, its arrays are a better concept. I just
> remarked that C code using pointers is sometimes more elegant than
> equivalent D code using arrays or ranges, and that it is a little bit
> unfortunate that we have all that while(*p && *p++ == --*q++){} stuff in
> the D grammar without the possibility to use it.

Well you can do that in D. The thing is to not do it implicitely because 
it is a dangerous behaviour and you should go into this only if you know 
what you are doing and not by mistake.


More information about the Digitalmars-d mailing list