Bug in lbound and ubound within sub?

General FreeBASIC programming questions.
dodicat
Posts: 6234
Joined: Jan 10, 2006 20:30
Location: Scotland

Bug in lbound and ubound within sub?

Postby dodicat » Jan 31, 2012 0:28

Code: Select all

 
sub test(array() as integer)
    print lbound(array(-200),1),ubound(array(200),1)
end sub

dim as integer a(1 to 5)
test(a())
sleep
 
dafhi
Posts: 1329
Joined: Jun 04, 2005 9:51

Re: Bug in lbound and ubound within sub?

Postby dafhi » Jan 31, 2012 1:46

Code: Select all

sub test(ary() as integer)
    print lbound(ary,1),ubound(ary(423545),1)
end sub

dim as integer a(1 to 5)
test(a())
? LBound(a(23455242),1)
Sleep
Richard
Posts: 2984
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Bug in lbound and ubound within sub?

Postby Richard » Jan 31, 2012 2:48

When using Lbound or Ubound you should pass the name of the array without brackets since that refers to the array descriptor. If you specify an element of the array then it may evaluate the address of that element when passing ByRef.

Code: Select all

Sub test(array() As Integer)
    Print Lbound(array, 1), Ubound(array, 1)
End Sub

Dim As Integer a(1 To 5)
test( a() )

Sleep
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Bug in lbound and ubound within sub?

Postby dkl » Jan 31, 2012 14:12

Strange, seems like the array index is allowed, but ignored:

Code: Select all

dim as integer x(0 to 0)
print lbound(x(0))
fxm
Posts: 9529
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Bug in lbound and ubound within sub?

Postby fxm » Jan 31, 2012 14:37

dkl wrote:Strange, seems like the array index is allowed, but ignored:

Code: Select all

dim as integer x(0 to 0)
print lbound(x(0))

It is similar to this bug request #3477036:
No error when pass to procedure any element instead of array

Return to “General”

Who is online

Users browsing this forum: MSN [Bot] and 1 guest