fwd ref

General FreeBASIC programming questions.
dafhi
Posts: 921
Joined: Jun 04, 2005 9:51

fwd ref

Postby dafhi » Aug 20, 2017 0:39

seems like this should work. at any rate, i thought of a work-around

Code: Select all

type circle_vars
  as single           x,y,rad
End Type

type                  FwdCS as circlestacker

type csbuf_vars
  as FwdCS ptr        cs
  declare sub         subtractive(byref p as circle_vars ptr)
end type
sub csbuf_vars.subtractive(byref p as circle_vars ptr)
  with cs->best(0)
 
  end with
end sub


type circlestacker
  as long             ub = -1
  as circle_vars      best(any)
end type
D.J.Peters
Posts: 7099
Joined: May 28, 2005 3:28
Location: Germany

Re: fwd ref

Postby D.J.Peters » Aug 20, 2017 1:59

Must be (a new) bug !
I used forward declares many times in the past without any problems.

Joshy

Code: Select all

type circle_vars
  as single x,y,rad
End Type

type circle_vars_t as circlestacker
 
type csbuf_vars
  declare sub subtractive(byref p as circle_vars ptr)
  as circle_vars_t ptr pcv
end type

sub csbuf_vars.subtractive(byref p as circle_vars ptr)
  print p->x
  print pcv->b.x
end sub

type circlestacker
  as long             ub
  as circle_vars      b
end type
fxm
Posts: 7270
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: fwd ref

Postby fxm » Aug 20, 2017 5:29

No bug.
'circlestacker' and ('best()' or 'b') must be defined before using them.
The error message (error 70: Incomplete type) corresponds to 'circlestacker' not defined before use it through the forward declaration.

Code: Select all

type circle_vars
  as single           x,y,rad
End Type

type                  FwdCS as circlestacker

type csbuf_vars
  as FwdCS ptr        cs
  declare sub         subtractive(byref p as circle_vars ptr)
end type

type circlestacker
  as long             ub = -1
  as circle_vars      best(any)
end type

sub csbuf_vars.subtractive(byref p as circle_vars ptr)
  with cs->best(0)
 
  end with
end sub

Code: Select all

type circle_vars
  as single x,y,rad
End Type

type circle_vars_t as circlestacker
 
type csbuf_vars
  declare sub subtractive(byref p as circle_vars ptr)
  as circle_vars_t ptr pcv
end type

type circlestacker
  as long             ub
  as circle_vars      b
end type

sub csbuf_vars.subtractive(byref p as circle_vars ptr)
  print p->x
  print pcv->b.x
end sub
Last edited by fxm on Aug 20, 2017 9:09, edited 1 time in total.
fxm
Posts: 7270
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: fwd ref

Postby fxm » Aug 20, 2017 8:24

These two examples are purely demonstrative (for the alleged bug) because they do not require the use of forward declaration.

Code: Select all

type circle_vars
  as single           x,y,rad
End Type

type circlestacker
  as long             ub = -1
  as circle_vars      best(any)
end type

type csbuf_vars
  as circlestacker ptr        cs
  declare sub         subtractive(byref p as circle_vars ptr)
end type

sub csbuf_vars.subtractive(byref p as circle_vars ptr)
  with cs->best(0)
 
  end with
end sub

Code: Select all

type circle_vars
  as single x,y,rad
End Type

type circlestacker
  as long             ub
  as circle_vars      b
end type

type csbuf_vars
  declare sub subtractive(byref p as circle_vars ptr)
  as circlestacker ptr pcv
end type

sub csbuf_vars.subtractive(byref p as circle_vars ptr)
  print p->x
  print pcv->b.x
end sub
D.J.Peters
Posts: 7099
Joined: May 28, 2005 3:28
Location: Germany

Re: fwd ref

Postby D.J.Peters » Aug 20, 2017 21:53

@fxm If classes are defined in seperate include files a compiler knows or read the interfaces.
That means "from my point of view" or in a perfect world :-)
after a forward declare a compiler must/can collect the implemented "missing"code in a second pass.
The same way are how forward declared jump labels are solved by an compiler.

Of course we don't live in a perfect world and your posted code looks more as workaround.

Joshy
dafhi
Posts: 921
Joined: Jun 04, 2005 9:51

Re: fwd ref

Postby dafhi » Aug 20, 2017 23:18

@fxm - if I were to swap the udts (your 2nd post) i'd have to forward reference csbuf_vars and it'd end up being the same issue. I'm only showing a fraction of my project code.

your first post might do the trick although I've implemented my own solution - an additional type to hold the data I'm trying to access, defined before everything
fxm
Posts: 7270
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: fwd ref

Postby fxm » Aug 21, 2017 7:32

fbc is a single-pass compiler.
When compiling "cs->best(0)" or "pcv->b.x", it must completely know the exact type of each variable.

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests