Passing array of function pointers as argument from udt member

General FreeBASIC programming questions.
Post Reply
shadow008
Posts: 86
Joined: Nov 26, 2013 2:43

Passing array of function pointers as argument from udt member

Post by shadow008 »

I'm not sure how to pass an array of function pointers as a parameter when the array is inside a UDT. Consider the following:

Code: Select all

sub test(inParam() as sub (x as integer))
    inParam(0)(3)
end sub

sub thing(x as integer)
    print x
end sub

type udt
    dim arr(10) as sub (x as integer)
end type

'Instances of udt's
dim udtPtr as udt ptr
udtPtr = new udt
udtPtr->arr(0) = @thing

dim udtInst as udt
udtInst.arr(0) = @thing

'Basic array
dim arr(10) as sub (x as integer)
arr(0) = @thing

test(arr())

'test(udtInst.arr()) 'Not allowed; syntax error
'test(udtPtr->arr()) 'Same

sleep
When uncommenting the bottom two calls to test(), I seem to get a non-descriptive syntax error
Syntax error, found '(' in 'test(udtInst.arr()) 'Not allowed; syntax error'
What's not allowed about this? It works just fine if it's accepting an array of integers.
I'm using fbc 1.10.0
fxm
Moderator
Posts: 12158
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Passing array of function pointers as argument from udt member

Post by fxm »

@Jeff,

Indeed, it looks like a bug.


[edit]

The above code works with :
test(udtInst.arr(0))
test(udtPtr->arr(0))

!!!

Otherwise, these 2 syntaxes work normally:
udtInst.arr(0)(3)
udtPtr->arr(0)(3)



The problem is more general and concerns any member array passed as an argument to a procedure:

Code: Select all

Type UDT
    Dim As Integer array(10)
End Type

Sub test(array() As Integer)
    Print array(5)
End Sub

Dim As UDT u
u.array(5) = 1234

Dim As Integer array(10)
array(5) = 5678

test(u.array())   '' 1234 : OK
test(u.array(0))  '' 1234 : but should be NOK because Type mismatch
test(u.array(5))  ''    0 : but should be NOK because Type mismatch
test(array())     '' 5678 : OK
'test(array(1))   '' Type mismatch : OK
'test(array(5))   '' Type mismatch : OK

Sleep
For the member array passed to the procedure, two syntaxes work, one of which should not work but produce a compile error !

When the member array is an array of procedure pointers, only the wrong syntax works !
(the two syntaxes, including the wrong, work for an array of any other pointer type)
Last edited by fxm on Jul 14, 2023 5:23, edited 6 times in total.
Reason: Bug analysis complemented.
fxm
Moderator
Posts: 12158
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Passing array of function pointers as argument from udt member

Post by fxm »

If you do not mind, I can fill in a bug report:
Incorrect syntax for a member array passed as argument to a procedure:
  • either in addition to the correct syntax a second erroneous syntax works (for any type of member array, except for procedure pointers),
  • or only the erroneous syntax works (for a member array of procedure pointers).
coderJeff
Site Admin
Posts: 4345
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Passing array of function pointers as argument from udt member

Post by coderJeff »

fxm wrote: Jul 14, 2023 6:44 If you do not mind, I can fill in a bug report:
Thank-you, that would be very helpful for any bug. That way it doesn't get lost in the forum, and assigns a tracking number for any related information (links to forum, local test files, change log, commits, etc).
fxm
Moderator
Posts: 12158
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Passing array of function pointers as argument from udt member

Post by fxm »

fxm
Moderator
Posts: 12158
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Passing array of function pointers as argument from udt member

Post by fxm »

Bug now fixed in the fbc version 1.20.0.
Post Reply