Reality drives me to write less clean code, sorry for mistakenly posting in D.announce
Charles D Hixson
charleshixsn at earthlink.net
Sat Oct 13 16:00:24 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.
>
>> To iterate over a D string, or any array, use foreach:
>>
>> foreach(c; text)
>> {
>> // do something with c
>> }
>
> .... or use foreach(dchar c; text) if you care about handling non-ascii
> properly.
I've seen several comments against it, but I don't know how
authoritative they were.
OTOH, you could easily be doing strange things to the garbage
collector. Even if it's safe, I wouldn't expect it to be
efficient (unless you turned off the garbage collector).
More information about the Digitalmars-d
mailing list