Re: question(s) about declaring variables



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


.



Relevant Pages

  • Re: Calling on Methods and Properties within Worksheet Modules
    ... The only reason why I can think of doing that, the Object data type is ... VB.NET base code, ... to other limitations and the lack of being able to bind at compile time. ... Declare l_wsh As Object ' note not as worksheet ...
    (microsoft.public.excel.programming)
  • Meta-literals
    ... are exact in Decimal and not exact in float. ... Unfortunately it is not very easy to access the Decimal data type. ... With Python 3000 major changes to the language are carried out anyway. ... compile time, and marshal the evaluated value into the *.pyc file. ...
    (comp.lang.python)
  • Re: REXML ... performance & memory usage ...
    ... It uses libxml2 for the parsing, and as such is quite speedy. ... I had to make two fixes to the source to get things to compile ... with the va_list data type without it. ...
    (comp.lang.ruby)
  • Re: derived types with parameter keyword
    ... data type. ... I could quote the standard-speak to show what restrictions are violated, ... Parameters are intended to be computable at compile time. ... operation involves executing a user-written procedure. ...
    (comp.lang.fortran)
  • A few basic c++ questions regarding 64 bit programming
    ... Will compiling on xp64 solve this? ... I looked but don't see a 64 bit data type ... I know Visual studio 2003 can compile for 64 when certain flags are set so I ...
    (microsoft.public.vstudio.general)