Type Forward?[SOLVED]

General FreeBASIC programming questions.
Loe
Posts: 323
Joined: Apr 30, 2006 14:49

Type Forward?[SOLVED]

Postby Loe » Dec 11, 2008 6:28

How to solve this situation?

Code: Select all

Type First
     a as sub(Byref v as Second)
EndType

Type Second
     a as sub(byref v as First)
EndType
Last edited by Loe on Dec 12, 2008 0:36, edited 1 time in total.
dkl
Site Admin
Posts: 3212
Joined: Jul 28, 2005 14:45
Location: Germany

Postby dkl » Dec 11, 2008 8:23

"type" allows to do "forward declarations", though I don't think it's possible without pointers:
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgTypeAlias

Code: Select all

type second_ as second

Type First
     a As Sub(Byval v As Second_ ptr)
End Type

Type Second
     a As Sub(Byval v As First)
End Type
Loe
Posts: 323
Joined: Apr 30, 2006 14:49

Postby Loe » Dec 11, 2008 9:02

Ah I see, so we refer to alias, second_ not second.
I just wonder why we dont have DECLARE for Type.
for the SUB or FUNCTION we just make DECLARE to access forward SUB or FUNCTION.

I ask this for my vTable UDT extractor project. there is a situation where a member of the class refer to the class which declare after their class.
to solve this I should edit manualy, move those class before refer by other class. its OK for the small TypeLib, but it'll take time for the huge TypeLib.
RayBritton
Posts: 306
Joined: Jun 02, 2005 7:11
Contact:

Postby RayBritton » Dec 11, 2008 12:25

I don't have much experience with this sort of thing, but couldn't you do this:

Code: Select all

type first_type
    b as any ptr
end type

type second_type
     a as first
end type

dim first as firs_type
dim second as second_type

first.b = &second


Although dkls solution seems a better one.
Last edited by RayBritton on Dec 11, 2008 15:13, edited 1 time in total.
stylin
Posts: 1253
Joined: Nov 06, 2005 5:19

Postby stylin » Dec 11, 2008 14:36

In procedure declarations, you can declare parameters of a forward-declared type by reference (ByRef as T) as well as by address (ByVal as T ptr).
Loe
Posts: 323
Joined: Apr 30, 2006 14:49

Postby Loe » Dec 12, 2008 0:40

My mistaken,
after seeing the code again, dkl's solution was enough for my case.
but still, considering DECLARE TYPE TypeName, as a request, if possible.

Thank you all.
Nexinarus
Posts: 146
Joined: May 28, 2005 6:08
Location: Everywhere
Contact:

Postby Nexinarus » Dec 12, 2008 6:34

i second Loe, i think there should be declare type typename, or allow:
type TypeName as TypeName

...

very useful for parsing/AST's

Return to “General”

Who is online

Users browsing this forum: No registered users and 6 guests