1 |
On Wed, Oct 29, 2008 at 10:13 PM, Jorge Peixoto de Morais Neto |
2 |
<please.no.spam.here@×××××.com> wrote: |
3 |
> The real problem is when you type |
4 |
> float real_number = 4e10; |
5 |
> int integer = real_number; |
6 |
> If your integer can only hold values up to 2^31 - 1 , the behavior of |
7 |
> the above code is undefined. |
8 |
> In a language like Python, everything either behaves as you intended, |
9 |
> of throws an exception. |
10 |
> This is why I say "In C, you must completely understand the behavior |
11 |
> of every statement or function, and you *must* handle the possibility |
12 |
> of errors". |
13 |
|
14 |
The line: |
15 |
int integer = real_number; |
16 |
will produce a warning. (or an error if you are smart enough to |
17 |
compile with -Werror) |
18 |
|
19 |
But, if you know that the real number will be small enough and you |
20 |
don't mind getting the floor of the float, you may wish to ignore the |
21 |
error. Like mr McKinnon said, c will allow you to do wrong things. |
22 |
|
23 |
Depending on what you are doing, the babysitting of python, may or may |
24 |
not be a problem. |
25 |
|
26 |
One thing I would like to know (not knowing python that well), is when |
27 |
you make an error in python, when will the exception be thrown? At the |
28 |
start of run-time, or when the guilty code is encountered? And what if |
29 |
that code is in a codebranch that gets executed 0.0005% of the time? |
30 |
|
31 |
Regards |
32 |
Dirk |