Qbasicnews.com

Full Version: Long or Integer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,

I looked in to the example "examples\Windows\gui\hello.bas".

I am a bit confused with the data types. The function WndProc looks like this:
Code:
function WndProc ( byval hWnd as long, _
                   byval message as long, _
                   byval wParam as long, _
                   byval lParam as long ) as integer

' .... other stuff

  WndProc = DefWindowProc( hWnd, message, wParam, lParam )
end function

Declaration of DefWindowProc in "inc\win\user32.bi":
Code:
Declare Function DefWindowProc Alias "DefWindowProcA" ( _
    ByVal hwnd As Integer, _
    ByVal wMsg As Integer, _
    ByVal wParam As Integer, _
    ByVal lParam As Integer  _
  ) As Integer

In the call...
Code:
WndProc = DefWindowProc( hWnd, message, wParam, lParam )
... Long variables are passed. The compiled program does work!

But would'nt it be cleaner code if the function arguments of WndProc would be declared as integers!

cu, helpy
Long = 32 bits
short = 16 bits

Integer = standard memory block size for processor/os.

In windows/linux integer = 32 bits (long)
In DOS integer = 16 bits

So within the confines of the current compiler and OS targets integer and long are interchangeable. However, if you are accessing files, etc. You will want to make sure you use short/long to get your 16/32 bits in case the new 64 bit processor makes the new integer a long-long.
In FreeBasic integer = long. They are both the same -synonyms. Both 32bit as well.
Quote:Long = 32 bits
short = 16 bits

Integer = standard memory block size for processor/os.

In windows/linux integer = 32 bits (long)
In DOS integer = 16 bits

Does that mean, that in the DOS Version of FB "integer" is 16 bits and in the Windows/Linux version of FB "integer" is 32 bits?

Does the size of the integer depends on the processor AND the operating system?

cu, helpy
No they are exactly the same, FB for DOS creates 32-bit pmode executables.

They only difference would be in 64-bit CPU's, if FB get ever ported..
maybe it would be more logical if to replace "longint" with "long"
and leave integer 32bit and long 64bit?
Thank you all for the information!


On Wikipedia I found: http://en.wikipedia.org/wiki/Long_integer
Quote:Long integer is a term used in computer science to describe a variable that can hold a positive or negative whole number, whose range is greater or equal to that of a standard integer on the same machine.

In practice it is usual for a long integer to require double the storage capacity of a standard integer, and consequently hold double the number of discrete values, although this is not always the case.

A variable defined as a long integer in one programming language may be different in size to a similarly defined variable in another. In some languages this size is fixed across platforms, whilst in others it is machine dependent. In some languages this data type does not exist at all.


cu, helpy
People will start to use LONG's on everything and claim FB is 4x slower than the crappiest BASIC compilers, no thanks..

64-bit integers will only be used by those that really need that, in C they are called "long long int", and "long" is just an alias for "int" too - on x86, that's it.

Operations on LONGINT's will be certainly faster than they were with LONG's in QB, as only division and modulo are function calls, all other operations are done inline, but they still much slower than with integer's, because in complex expressions there will be loads of register spills and so on - FB uses the ALU to do the operations, not a hack like PB does, using the FPU to do the hard work.
LONGINT are not so slow, if you use them with care..

I modified the prime generator by Rich Geldreich I once posted there http://forum.qbasicnews.com/viewtopic.php?t=8463
using LONGINT only where absolutely needed, and the results were:

Found 5,761,455 Primes from 1 to 100,000,000
With integer it took 17,4 seconds and with LONGINT was 21,3 seconds
So a slowdown of just a 23%.

It's true the algorithm does not use division at all...
Cool, it didn't have any complex expression too, no registers spills were probably needed.

PB calls 64-bit integers QUAD, XBasic GIANT, in Pascal it's Int64 or QWord, in C it's __int64 or long long int, there's not really a name standard to follow.. LONGINT
Pages: 1 2