Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] kprintf with user formatters
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] kprintf with user formatters
On Fri, 2004-07-23 at 01:39, Pierre Weis wrote:

> For instance, you would have a hard time to persuade a
> matematician that
> 
> 0 * ln (0)
> 
> is well-defined and evaluates to 0, ``because ln (0) has not to be
> considered at all given the left operand''.

Actually, this IS the case in many languages such as C.
0 is not in the domain of ln. Therefore, the result is undefined
when you apply ln to 0 because you're applying a function to a value
outside its domain. In language standards it is sometimes
said that the result is undefined in such cases, which means
that the compiler can generate code to do anything it wants
in such cases.

In particular it can return 0 and remain conforming
and therefore it can apply the shortcut evaluation.

This is NOT the case if the language standard specifies
an exception must be thrown, or NaN or +Inf returned,
which is generally a very bad idea precisely because it 
makes the semantics determinate and thus defeats the
optimisation which could otherwise be obtained by
using the usual mathematical law 0 * x = 0.

C is very careful to leave lots of things undefined.

This issue actually arose directly on the C++ Standards
Committee, except the function was division not ln.
The question was whether a compiler was allowed and/or
required to issue a diagnostic error message given:

main() { return 1/0; }

Note that it is possible to prove IN THIS CASE
that the program will always fail by dividing by zero.

However, it isn't always so obvious -- so you simply cannot
require a diagnostic. Indeed, one can argue -- and
someone DID argue -- that even if the program always
fails when executed .. who knows if it is executed?

The code must be generated, C compiler can issue a warning
but it is NOT allowed to reject the program. It must
actually generated code which can be executed .. even though
that code can do anything (Aas far as I can remember that
was the interpretation..)

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



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