Reality drives me to write less clean code, sorry for mistakenly posting in D.announce

Bill Baxter dnewsgroup at billbaxter.com
Thu Oct 11 20:16:17 PDT 2007


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.



More information about the Digitalmars-d mailing list