Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] assertions and branch prediction
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] assertions and branch prediction
>From: james woodyatt <jhw@wetware.com>

>	match p with
>	| A -> ...; ()
>	| B -> ...; ()
>	| _ -> assert false
>
>Then I hit upon the idea of rewriting it this way:
>
>	assert (p = A || p = B);
>	match p with
>	| A -> ...; ()
>	| B -> ...; ()
>	| C -> ()
>
>My thinking was that I would rather pay up front with a more expensive 
>assertion, one that can be stripped out later with the -noassert option, 
>rather than pay at deployment with code (for raising the Assert_failure 
>exception) that I've eventually proven will not be executed.

You can have the best of both worlds by writing it like this:

	match p with
	| A -> ...; ()
	| B -> ...; ()
	| _ -> assert (not true); ()


As for "assert false" with -noassert, you're not really supposed to
catch the Assert_failure exception (unless you really know what
you're doing), so it should result in the immediate termination of
your program anyway.

-- Damien
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr