Re: What about turbos?



In article <46e6956f@xxxxxxxxxxxxxxxxxxxxxx>, craig_stuntz@xxxxxxxxxxxxx
says...
Jolyon Smith wrote:

In .net of course, such unchecked casts are not possible.

That's not quite right, and that makes the rest of your post confused.
"Hard" casts -- () casts in Delphi -- are possible (they just return
nil if the type check fails).

Why use the word "hard" when I specifically used the word "unchecked"?
(actually, I may have used the term myself elsewhere in the same post or in
another post, but in any event your apparent notion of a "hard" cast isn't the
same as mine)

In Delphi.32 TSomeClass(someObj) will simply satisfy a compile-time check - no
actual conversion and no runtime checking is performed (except in the case of
"magic" casts, e.g. String(PChar)).

In Delphi.NET TSomeClass(someObj) satisfies a compile time check but ALSO
incurs a runtime check. Not unique to Delphi of course : this is a net-ism.

It is not possible (should I perhaps have added: "in managed code" ?) to
typecast-without-checking in .NET


Put another way, TSomeClass(someObj) has no runtime cost in Delphi.32, but has
a type-checking cost in Delphi.Net


The truly stupid thing (imo) being that you incurr that type check even when
you know for sure that the check is unnecessary which will be (Ok, "should
be" <g>) the overwhelmingly vast majority of cases.


Type checking with a .NET generic is /always/ and /only/ at compile
time. Type checking with a cast is at runtime. Note that the generic
TList<T> doesn't require any casting in its implementation, on either
platform.

As maybe - I haven't really thought about the .NET generics implementation as
such, except in so far as the Delphi.32 implementation is presumably modelled
on that implementation. My concern is with the potential (as yet quantified
and perhaps even unproven) performance penalty that using a generic in Delphi
will incurr vs a hand-rolled typesafe implementation.

But what you say makes sense - since casting is unavoidably checked in .net,
the implementation details of an instantiated generic is presumably one of the
few places that the CLR can assume type safety has been absolutely assured.


I'm not quite certain what you mean here, but if you're saying that a
TList<TCustomer>.Add does a runtime type check on the value you pass it
in the absence of a cast, it's wrong. The type checking is at compile
time.

And at runtime? In Delphi.32 it has to doesn't it? Precisely _because_ you
can fool the compiler with an unchecked cast.

fooList: TList<TFoo>;

fooList.Add(TFoo(someBar));

In the .NET implementation the smoky internals of the instantiate TList<T> can
reliably know that they are dealing with a certain type since the runtime will
ensure that they get that type (or NIL as you pointed out).

In Delphi.32 the smoky internals of TList can make no such assumption since a
foolhardy developer may have hoodwinked the compiler.


I'm not saying this is absolutely why it has to happen, or indeed that I know
for a fact that it does (or will) happen.

I am suggesting that this *might* be one reason that such additional type-
checking is needed, given the fact that it was mentioned by someone that
presumably is better placed to know that I that some "additional" (his word)
type checking *is* performed.

<shrug>
.



Relevant Pages

  • Re: Why does this object need to be cast?
    ... Having just attended an all day 'generics' education day, ... why do I need to cast to comboboxes? ... >> know that this is an object of type combobox? ... > Example with cast operators on System.Byte and System.Int32: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Compiling C DLLs for reuse in MC++?
    ... the /clr option does not compile ... unable to perform cast from void* to classname*. ... you can't cast between data and function pointers in ...
    (microsoft.public.dotnet.languages.vc)
  • Re: .NET 2.0 to be launched on Nov 8
    ... native for generics to work. ... > and probably Delphi for Win32 RSN. ... > do when they compile a template, ...
    (borland.public.delphi.non-technical)
  • mex compile error
    ... I installed Xcode 3.2.4 after the matlab. ... But when I compile a test file 'yprime.c', ... yprime.c:96: warning: assignment makes pointer from integer without a cast ...
    (comp.soft-sys.matlab)
  • Re: UI Threads in C++/CLI (only partially answered, probably a bug)
    ... Marcus ... > this code should not even compile. ... > In contrast to my code, your code (which does the same cast) ... >> An unhandled exception of type ...
    (microsoft.public.dotnet.languages.vc)