Reality drives me to write less clean code, sorry for mistakenly posting in D.announce
Mike Parker
aldacron71 at yahoo.com
Fri Oct 12 00:06:46 PDT 2007
Bill Baxter wrote:
> Mike Parker wrote:
>> davidl wrote:
>>>
>>> First practice:
>>>
>>> char[] text;
>>> char* p;
>>> char* end;
>>>
>>
>> Pointer arithmetic in D is a no-no, unless you are using memory
>> allocated outside of the GC.
>
> That's news to me. There's nothing wrong with using pointers, it's just
> more verbose and error prone than foreach.
Of course there's nothing wrong with /using/ pointers, but pointer
arithmetic is one item in a list of 'Undefined Behavior' regarding
pointers to GC memory. See the page
http://www.digitalmars.com/d/garbage.html (section titled Pointers and
the Garbage Collector).
This isn't really an issue in the present since the current GC doesn't
move anything around, AFAIK. But it's still a bad habit to get into (or
a good one to get out of for people with C backgrounds) and doesn't do
much for future-proofing.
More information about the Digitalmars-d
mailing list