logo       

RE: peekCString stack overflow: msg#00009

lang.haskell.glasgow.bugs

Subject: RE: peekCString stack overflow


> 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


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise