fwd ref

General FreeBASIC programming questions.
Post Reply
dafhi
Posts: 1652
Joined: Jun 04, 2005 9:51

fwd ref

Post by dafhi »

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: 8586
Joined: May 28, 2005 3:28
Contact:

Re: fwd ref

Post by D.J.Peters »

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

Re: fwd ref

Post by fxm »

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

Re: fwd ref

Post by fxm »

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: 8586
Joined: May 28, 2005 3:28
Contact:

Re: fwd ref

Post by D.J.Peters »

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

Re: fwd ref

Post by dafhi »

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

Re: fwd ref

Post by fxm »

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