Bug in lbound and ubound within sub?

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

Bug in lbound and ubound within sub?

Post by dodicat »

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: 1641
Joined: Jun 04, 2005 9:51

Re: Bug in lbound and ubound within sub?

Post by dafhi »

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: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Bug in lbound and ubound within sub?

Post by Richard »

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: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Bug in lbound and ubound within sub?

Post by dkl »

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
Moderator
Posts: 12108
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Bug in lbound and ubound within sub?

Post by fxm »

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
Post Reply