caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ken Rose <kenrose@tfb.com>
To: cashin@cs.uga.edu
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Unix.lseek versus Pervasives.pos
Date: Wed, 19 Mar 2003 10:55:53 -0800	[thread overview]
Message-ID: <3E78BD39.B6499AC0@tfb.com> (raw)
In-Reply-To: <877kavryp3.fsf@cs.uga.edu>

cashin@cs.uga.edu wrote:
> 
> Flushes are for writes, but even when using a test program that just
> reads, zero is returned when it appears that it shouldn't return zero.
> Compare the short ocaml program below to the comparable C version.
> 
> The ocaml version has lseek returning position zero after reading 10
> bytes from the file.
> 
>   ecashin@meili seek-tell$ ./test
>   after reading 10 chars: "let main =", position is 0
>   ecashin@meili seek-tell$ cat main.ml
>   let main =
>     let fd = Unix.openfile "main.ml" [Unix.O_RDONLY] 0
>     and buf = String.create 1024 in
>     Printf.printf "after reading %d chars: \"%s\", position is %d\n"
>       (UnixLabels.read fd ~buf ~pos:0 ~len:10)
>       buf
>       (UnixLabels.lseek fd 0 ~mode:Unix.SEEK_CUR)
>   ;;
> 
>   main
> 

It looks like you're getting bitten by the order of evaluation of
function arguments.  

$ cat main.ml
let main = 
    let fd = Unix.openfile "main.ml" [Unix.O_RDONLY] 0 
    and buf = String.create 1024 in
    let r = (UnixLabels.read fd ~buf ~pos:0 ~len:10) in
    Printf.printf "after reading %d chars: \"%s\", position is %d\n"
      r
      buf
      (UnixLabels.lseek fd 0 ~mode:Unix.SEEK_CUR)
  ;;

main

$ ./a.out
after reading 10 chars: "let main =", position is 10
$

 - ken

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2003-03-19 18:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-19 18:36 cashin
2003-03-19 18:48 ` Nicolas George
2003-03-19 19:01   ` cashin
2003-03-19 18:55 ` Ken Rose [this message]
2003-03-19 19:08 ` Basile STARYNKEVITCH
     [not found] <46CF368E-5912-11D7-8289-000A95773ED2@rouaix.org>
2003-03-18 17:35 ` Shivkumar Chandrasekaran
2003-03-18 17:39 ` Shivkumar Chandrasekaran
2003-03-19 20:27   ` Xavier Leroy
  -- strict thread matches above, loose matches on Subject: below --
2003-03-17 22:45 Shivkumar Chandrasekaran
2003-03-18  6:54 ` Basile STARYNKEVITCH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3E78BD39.B6499AC0@tfb.com \
    --to=kenrose@tfb.com \
    --cc=caml-list@inria.fr \
    --cc=cashin@cs.uga.edu \
    --cc=rose@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).