Re: out of memory, even tho remembered nothing!
- Posted by jimcbrown (admin) Oct 18, 2012
- 1586 views
Well, anyhow, this fails to run properly also:
junk = gets(readfile) while sequence(junk) do size += length(junk) puts(1,sprintf("%d",size)&"\r") junk = gets(readfile) end while
I just tried this, and it appears to work correctly for me. It gets the number of bytes in the file and reports it correctly, and then quits.
What behavior is it exhibiting for you that causes you to declare that it has failed?
I looked in io.e for what EOF is when gets() hits the end of the file:
From docs on gets() -
and from io.e -
You already know this, but just so other readers of this thread are clear: gets() returns a value that is equal to the public constant EOF in io.e, but it doesn't actually use that constant. It merely returns -1.
And so i am still tripping over typecasting.
I don't see how.
To me, -1 is not a sequence,
Agreed. When I run your code, it seems to confirm that this is the case (that -1 is not a sequence).
nor should it be TRUE.
I disagree. -1 should be TRUE since -1 is the set of bits such that all bits are equal to 1.
To avoid the horrors like this, the following convoluted while must be used:
junk = gets(readfile) while not equal(-1,junk) do size += length(junk) puts(1,sprintf("%d",size)&"\r") junk = gets(readfile) end while
Avoid horrors like what? Why must this be used, instead of your original code above?
If it's voteable, i vote for replacing "while not equal(-1,junk) do" with "while junk do".
Same here. I'm sure we could enhance the parser so that, if gets() is being called inside an if or while statement (or something akin to that) it returns 0 on EOF instead of -1, as well as making any sequence from gets() counted as a TRUE value.
I'd hate to see -1 become a FALSE value, though.