Re: Something that really annoys me in Delphi ...
From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 01/07/04
- Next message: Duncan Murdoch: "Re: Something that really annoys me in Delphi ..."
- Previous message: Maarten Wiltink: "Re: Execute From Shell"
- In reply to: Nicolai Hansen: "Re: Something that really annoys me in Delphi ..."
- Next in thread: Rob Kennedy: "Re: Something that really annoys me in Delphi ..."
- Reply: Rob Kennedy: "Re: Something that really annoys me in Delphi ..."
- Reply: Bruce Roberts: "Re: Something that really annoys me in Delphi ..."
- Reply: Dr John Stockton: "Re: Something that really annoys me in Delphi ..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 7 Jan 2004 22:50:44 +0100
"Nicolai Hansen" <nic@aub.dk> wrote in message
news:d96764ff.0401070627.799788e1@posting.google.com...
>> Delphi could not predict all modifications of your GoAction variable.
>> What about the following example, which is quite valid:
>>
>> GoAction:=gaWrite;
>> ...
>> GoAction:=Succ(GoAction);
>>
>> In this case, your function will have undefined result.
> Interesting... A function that works on enumerations without range
> checking.
Only if you turn it off in the compiler options. The code is
(syntactically) valid, but it will cause a run-time error in
any program of mine. I simply never turn off all the debugging
options.
> This puzzles me. Someone, please again, mention to me that Delphi is
> strongly typed language and this is its main advantage to C.
Pascal is a strongly typed language and this is one of its main
advantages over C.
> Functions like the mentioned should have big red warning signs posted
> all around it "-this method is using unsafe typecasts and might give
> invalid results-" or something like that ;)
Calling Succ is not ordinarily considered to involve any typecasting.
But you're right, it does - in the sense that the compiler apparently
simply emits an INC instruction on the storage for the expression,
which indeed amounts to a cast to, well, perhaps not Integer but DWORD,
and a cast back.
I think this is reasonable. CPUs don't have any fundamental operation
with the same semantics. The semantics are that the function returns
the next higher value in the type's range, if it exists, and is not
defined (and even invalid to call at all) otherwise. But enforcing
the invalidity of calling Succ(High(.)) requires a range check, and
due to technical limitations this means having range checking enabled
globally.
There is a philosophical question here. Is it permissible to call
Succ on a value that has no successor, if one never thereafter evaluates
the return value? If a type rolls over in a forest where there's no-one
to see it, does it make a crash?
Groetjes,
Maarten Wiltink
- Next message: Duncan Murdoch: "Re: Something that really annoys me in Delphi ..."
- Previous message: Maarten Wiltink: "Re: Execute From Shell"
- In reply to: Nicolai Hansen: "Re: Something that really annoys me in Delphi ..."
- Next in thread: Rob Kennedy: "Re: Something that really annoys me in Delphi ..."
- Reply: Rob Kennedy: "Re: Something that really annoys me in Delphi ..."
- Reply: Bruce Roberts: "Re: Something that really annoys me in Delphi ..."
- Reply: Dr John Stockton: "Re: Something that really annoys me in Delphi ..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|