Re: question(s) about declaring variables
- From: "Michael C" <mculley@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 28 Jun 2005 09:49:19 +1000
"MikeD" <nobody@xxxxxxxxxxx> wrote in message
news:%23eokBo2eFHA.1136@xxxxxxxxxxxxxxxxxxxxxxx
> I have to question that. Any performance hit would indeed be minimal (if
> existant, or at least measureable, at all), but I don't think they'd
> compile exactly the same. It's two different things. One is type-casting a
> literal value to a specific data type and this occurs at compile time.
> Another is *converting* a literal value from one data type to a different
> data type and this occurs at runtime (and subsequently happens every time
> the code is executed).
The compiler must optimise it.
> I really think you're mistaken. I don't see how they can compile
> identically.
I found a little trick a few years ago, if the compiler finds 2 functions
are exactly the same it optimises out one of the functions. You can check it
has done this by finding the address of each function using the AddressOf
operator. If the 2 functions are identical they will have the same address
once fully compiled. Give it a try. When in the IDE the functions have
different addresses but once compiled they have the same address
Put this code in a module
Public Function A(ByVal X as Long) as Long
A = X * 1000&
End Function
Public Function B(ByVal Y as Long) as Long
B= X * CLng(1000)
End Function
And this code in a form:
private sub Form_Load()
Me.Caption = AddOf(AddressOf A) & " " & AddOf(AddressOf B)
End Sub
Private Function AddOf(ByVal Address as Long) as Long
AddOf = Address
End Function
>
> --
> Mike
> Microsoft MVP Visual Basic
>
>
.
- Follow-Ups:
- Re: question(s) about declaring variables
- From: Duane Bozarth
- Re: question(s) about declaring variables
- References:
- question(s) about declaring variables
- From: Steve Easton
- Re: question(s) about declaring variables
- From: Mike D Sutton
- Re: question(s) about declaring variables
- From: Steve Easton
- Re: question(s) about declaring variables
- From: Mike D Sutton
- Re: question(s) about declaring variables
- From: Larry Serflaten
- Re: question(s) about declaring variables
- From: Michael C
- Re: question(s) about declaring variables
- From: spacewarp
- Re: question(s) about declaring variables
- From: Michael C
- Re: question(s) about declaring variables
- From: MikeD
- question(s) about declaring variables
- Prev by Date: Re: question(s) about declaring variables
- Next by Date: Re: question(s) about declaring variables
- Previous by thread: Re: question(s) about declaring variables
- Next by thread: Re: question(s) about declaring variables
- Index(es):
Relevant Pages
|