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: Christopher Quinn <cq@h...>
Subject: Re: [Caml-list] assertions and branch prediction
May I ask how 
| _ -> assert (not true); ()

is different from 

| _ -> assert false; ()

???

Thanks,
chris









Damien Doligez wrote:

>>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
>

-- 
rgrds,
Chris Quinn



-------------------
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