> Off the top of my head:
>
> 1) Compute length of C string.
> (As usual, need to use seq on the '+1' argument.)
> 2) Scan from right to left, constructing the list.
Ah yes, that's the trick I was forgetting about, thanks.
> Or, since making two passes seems ugly, construct the list in
> reverse and then
> return the reversed list:
>
> peekCString ptr = peekCString' ptr []
> where
> peekCString' ptr r = do
> c <- peek ptr
> if c == '\0'
> then return (reverse r)
> else peekCString' (ptr+1) (c:r)
>
> I have a nasty feeling that reverse doesn't work in constant
> stack space though so this probably doesn't work.
That's right: using reverse doesn't help.
Cheers,
Simon
_______________________________________________
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs