From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id DAA22900 for caml-redistribution; Thu, 8 Jul 1999 03:41:03 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA02338 for ; Sat, 3 Jul 1999 00:13:35 +0200 (MET DST) Received: from firewall.f5.com (f5.com [207.17.117.200]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id AAA19543 for ; Sat, 3 Jul 1999 00:13:33 +0200 (MET DST) Received: by firewall.f5.com; id OAA09589; Fri, 2 Jul 1999 14:39:56 GMT Received: from knotwell.dev.net(192.168.101.138) by firewall.f5.com via smap (4.1) id xma009584; Fri, 2 Jul 99 14:39:55 GMT Received: (from knotwell@localhost) by knotwell.f5.com (8.9.3/8.9.3) id PAA08315; Fri, 2 Jul 1999 15:30:34 -0700 From: " MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14205.15754.427409.474325@knotwell.f5.com> Date: Fri, 2 Jul 1999 15:30:34 -0700 (PDT) To: caml-list@inria.fr Subject: small code problem X-Mailer: VM 6.71 under 21.2 "Boreas" XEmacs Lucid (beta10) Reply-To: knotwell@f5.com Sender: weis Hello all-- I'm having a problem with a core dump due to an uncaught exception. The following snippet of code best illustrates the problem: let usage = lazy (Printf.printf "Usage: %s file\n" Sys.argv.(0); exit ~-1);; let filename = try Sys.argv.(1) with Invalid_argument("Array.get") -> Lazy.force usage;; When I compile using the byte-code compiler, it seems to work fine. [knotwell@knotwell stock]$ ocamlc junk.ml [knotwell@knotwell stock]$ ./a.out Usage: ./a.out file [knotwell@knotwell stock]$ On the other hand, when I compile with the optimizing compiler, I receive the following: [knotwell@knotwell stock]$ ocamlopt junk.ml [knotwell@knotwell stock]$ ./a.out Segmentation fault (core dumped) [knotwell@knotwell stock]$ When I change the code slightly: let usage = lazy (Printf.printf "Usage: %s file\n" Sys.argv.(0); exit ~-1);; let filename = try Sys.argv.(1) with _ -> (* note the pattern matching change *) Lazy.force usage;; I then get correct results: [knotwell@knotwell stock]$ ocamlopt junk.ml [knotwell@knotwell stock]$ a.out Usage: a.out file [knotwell@knotwell stock]$ Why do the two compilers exhibit different behaviors with the same code? As an aside, I don't particular like my use of lazy and force. Is there a cleaner way do the same thing? Thanks. --Brad