How to fix error 177 ???

General FreeBASIC programming questions.
fxm
Posts: 8962
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: How to fix error 177 ???

Postby fxm » Dec 08, 2018 14:41

paul doe wrote:
fxm wrote:In FreeBASIC, anything that can be done with pointers can be done with references (because a reference is the dereferencing of an internal pointer, but accessible by user).

Not true, because there's no orthogonality between references and pointers

Yes in that case, because non static reference field in UDT are not yet supported in FreeBASIC.
Possible future syntax:

Code: Select all

type SomeObject
  public:
    declare constructor( _
      byref as ISomething )
    declare destructor()
 
  private:
    declare constructor()
   
    byref m_something as ISomething = *cptr(ISomething ptr, 0)
end type
Last edited by fxm on Dec 08, 2018 15:07, edited 1 time in total.
fxm
Posts: 8962
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: How to fix error 177 ???

Postby fxm » Dec 08, 2018 14:42

dodicat wrote:fxm
your example gives
Compiler output:
Aborting due to runtime error 12 ("segmentation violation" signal) in 32 bit gas and gcc
And compile failed with no reason shown in 64 bit gcc.

Bug now fixed in Rev 1.06.
Munair
Posts: 834
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Re: How to fix error 177 ???

Postby Munair » Dec 08, 2018 16:59

paul doe wrote:Or simply allow late binding of references to interfaces.

That would be my preference.

In general, it would be great if FB would implement real classes and allow explicit instantiation.
paul doe
Posts: 913
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: How to fix error 177 ???

Postby paul doe » Dec 08, 2018 20:38

Munair wrote:In general, it would be great if FB would implement real classes...

And what would constitute a 'real' class for you? The only thing I miss dearly from other languages with a similar object model is the ability to inherit multiple interfaces. Oh, and friend and private classes. That is quite enough to create a pretty solid and cohesive object model.

The class keyword should be implemented already, even if that simply means a type that extends object by default:

Code: Select all

type Whatever extends Object
...
end type

'' Equivalent to
class Whatever
...
end class

Munair wrote:...and allow explicit instantiation.

You can do so already:

Code: Select all

var anObject = new Foo( blah )

But of course, what thou explicitly instantiate, thou shalt explicitly de-instantiate. Not that it's a great concern anyways, since in general you always want to be in control of these two essential operations. Another reason to simply go the pointer way when dealing with objects in FreeBasic.
Munair
Posts: 834
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Re: How to fix error 177 ???

Postby Munair » Dec 08, 2018 20:53

There was recently a discussion about this: viewtopic.php?f=17&t=23584&start=105#p255056
D.J.Peters
Posts: 7667
Joined: May 28, 2005 3:28

Re: How to fix error 177 ???

Postby D.J.Peters » Dec 09, 2018 1:06

Code: Select all

#ifdef class
 #undef class
 #define class type
#endif

type aType
  as integer i
end type 

class aClass extends object
  declare abstract sub implement_me
  declare virtual  sub overwrite_me
  as aType i_share_it
end class

sub aClass.overwrite_me
  print "you don't overwrote me: " & i_share_it.i
end sub

class cool extends aClass
  declare constructor
  declare sub implement_me
  declare sub overwrite_me
end class
constructor cool
  i_share_it.i = 123
end constructor
sub cool.implement_me
  print "implemeneted by cool: " & i_share_it.i
end sub 
sub cool.overwrite_me
  print "overwritten by cool: " & i_share_it.i
end sub
Munair
Posts: 834
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Re: How to fix error 177 ???

Postby Munair » Dec 09, 2018 7:18

fxm wrote:In FreeBASIC, anything that can be done with pointers can be done with references (because a reference is the dereferencing of an internal pointer, but accessible by user).

Not quite, references to objects within objects cannot be null referenced (yet) without using pointers. Only independent or first level objects can be null referenced. This is why I ask for a class implementation away from TYPE objects where instantiating and de-instantiating must be done explicitly, so that the programmer has full control over objects, when they are initialized, their constructors called etc...
fxm
Posts: 8962
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: How to fix error 177 ???

Postby fxm » Dec 09, 2018 7:31

Munair wrote:references to objects within objects cannot be null referenced (yet) without using pointers.

Can you give a simple example of this handicap, to see if we can still do something?
Munair
Posts: 834
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Re: How to fix error 177 ???

Postby Munair » Dec 09, 2018 8:12

Code: Select all

type tOne extends object
   s as string
   declare constructor()
end type

constructor tOne()
   s = "constuctor tOne called"
end constructor

type tTwo extends object
   s as string
   One as TOne
   declare constructor()
end type

constructor tTwo()
   ' cannot be made dynamic
   'One = new tOne
   'delete One
   s = "constuctor tTwo called"
end constructor

' also initializes tOne()
dim two as tTwo
print two.One.s
print two.s

' causes a segmentation fault
two.One = *cptr(TOne ptr, 0)

Even if there would be a work-around for the null-reference, it doesn't change the fact that FB instantiates all nested objects automatically with the creation of the parent object. If I would want a child object to be instantiated later on, say as the result of a function, FB would not allow me to do so.

This example has a tiny constructor tOne(), but larger constructors are not cheap and it would (potentially) be much more efficient to instantiate them explicitly where needed.
fxm
Posts: 8962
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: How to fix error 177 ???

Postby fxm » Dec 09, 2018 8:51

The first problem is that 'two.One' is not declared as reference because 'One' is a non-static normal declared field.
'One' field should be declared as non-static reference (with syntax for example: 'byref One as TOne ...'), but FreeBASIC does not support it at present time in an UDT.
After that, it may not be enough!
mrminecrafttnt
Posts: 85
Joined: Feb 11, 2013 12:23

Re: How to fix error 177 ???

Postby mrminecrafttnt » Dec 09, 2018 11:31

Ok, i think now waht is do, i've fixed this with:

Code: Select all

function Inventory.getObj(ObjName as string) as InventoryObjectData
    dim as integer id = search_id(ObjName)
    if id = -1 then
        print "Object not found"
        dim as InventoryObjectData EmptyObject
        return EmptyObject
    else
        return ObjectData(id)
    end if
end function

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest