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 BAA02332 for caml-redistribution; Fri, 9 Jul 1999 01:46:17 +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 BAA24913 for ; Fri, 9 Jul 1999 01:19:46 +0200 (MET DST) Received: from beach.frankfurt.netsurf.de (beach.frankfurt.netsurf.de [194.64.181.2]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id BAA01958 for ; Fri, 9 Jul 1999 01:19:39 +0200 (MET DST) Received: from schneemann.darmstadt.netsurf.de (board-14.darmstadt.netsurf.de [194.163.86.142]) by beach.frankfurt.netsurf.de (8.8.5/8.8.5) with ESMTP id BAA24787; Fri, 9 Jul 1999 01:19:37 +0200 (MET DST) Received: from localhost (localhost [[UNIX: localhost]]) by schneemann.darmstadt.netsurf.de (8.8.8/8.8.8) id BAA00037; Fri, 9 Jul 1999 01:19:27 +0200 From: Gerd Stolpmann Reply-To: Gerd.Stolpmann@darmstadt.netsurf.de Organization: privat To: knotwell@f5.com, caml-list@inria.fr Subject: Re: small code problem Date: Fri, 9 Jul 1999 00:49:19 +0200 X-Mailer: KMail [version 1.0.17] Content-Type: text/plain References: <14205.15754.427409.474325@knotwell.f5.com> MIME-Version: 1.0 Message-Id: <99070901192505.28040@schneemann> Content-Transfer-Encoding: 8bit Sender: weis On Sat, 03 Jul 1999, Brad Knotwell wrote: >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]$ On an x86 architecture I get a different result: Fatal error: uncaught exception Invalid_argument("out-of-bound array or string access") This means that there are two problems: - The segfault - The different exceptions raised by the bytecode and the native compiler. >As an aside, I don't particular like my use of lazy and force. Is >there a cleaner way do the same thing? let usage() = Printf.printf "Usage: %s file\n" Sys.argv.(0); exit ~-1;; let filename = match Sys.argv with [| |] -> failwith "You have a silly operating system" | [| _ |] -> usage() | _ -> Sys.argv.(1) This solution avoids that Invalid_argument must be caught which is better style. It is almost always a bad idea to trap Invalid_argument, Out_of_memory, Stack_overflow, and Division_by_zero, as these exceptions are thought as last resort that indicates a bad system state that must not happen but happened. It is better to design the program such that it never runs into conditions that raise these exceptions, and if they happen nevertheless, you missed something. Gerd -- ---------------------------------------------------------------------------- Gerd Stolpmann Telefon: +49 6151 997705 (privat) Viktoriastr. 100 64293 Darmstadt EMail: Gerd.Stolpmann@darmstadt.netsurf.de (privat) Germany ----------------------------------------------------------------------------