Hi everyone,

I'm trying to do some simple I/O with Clean and I've run into some very strange behaviour which I think is a bug in the 64-bit edition of Clean.

Consider this program (Test.icl):

  module Test

  import StdEnv

  doCase :: *File Int -> *File
  doCase fp c
  # (ok, n, fp) = freadi fp
  = fwrites ("Case #" +++ toString c +++ ": "
              +++ toString n +++ " (" +++ toString ok +++ ")\n") fp

  Start world
  # (fp, world) = stdio world
  = fclose (do (freadi fp)) world
  where
      do (False, _, fp) = fp
      do (True,  n, fp) = foldl doCase fp [1..n]

And the following data file (test.in):

  3
  123
  456
  789

When I try to compile and run this, the result is as follows:

  $ clm Test
  Compiling Test
  Warning [StdFile.abc,11,stdio;33]: no inline code for this rule
  Warning [StdFile.abc,11,fclose;30]: no inline code for this rule
  Generating code for Test
  Linking Test

  $ ./a.out < test.in
  Case #1: 140733193388155 (True)
  Case #2: 456 (True)
  Case #3: 789 (True)
  (True,65536)
  Execution: 0.00  Garbage collection: 0.00  Total: 0.00

Of course this is very strange: I expected Case #1 to print 123. As you can see, reading does succeed, and the following values are read correctly. Now, 140733193388155 is 0x7fff0000007b and 0x7b is indeed 123, so it appears that freadi actually only reads a 32-bit integer and leaves garbage in the upper 32 bits of the resulting integer.

Is this a known problem? Any suggestions on how to fix this or work around it?

Kind regards,
Maks Verver.
_______________________________________________
clean-list mailing list
[email protected]
http://mailman.science.ru.nl/mailman/listinfo/clean-list

Reply via email to