[Gambas-devel] Proper way to the current object

Randall Morgan rmorgan62 at ...176...
Sun Feb 12 00:41:40 CET 2012


Specifically,

In the GslComplex_Add method the line:

// Save the values of the current object into a.
GSL_SET_COMPLEX(&a, THIS->number.real, THIS->number.imagined);

Causes a seg fault while when replaced with:

 GSL_SET_COMPLEX(&a, 10.0, 12.0);

The method functions as expected.

Testing seems to indicate that the value of THIS is null. THIS is defined
in the class header file as:

#define THIS ((GSLCOMPLEX *)_object)

It was my understanding that the above line would result in a pointer to
the current object. And in the get/set property methods it seems to work
that way.




2012/2/11 Benoît Minisini <gambas at ...1...>

> Le 09/02/2012 15:56, Randall Morgan a écrit :
> > Hi Benoit,
> >
> > I am a bit perplexed. I have some code that works and some that
> > doesn't... I think I have been looking at the code too long to see the
> > issue. So I was hoping your eyes might help.
> >
> > I have used:
> >
> > #define THIS ((GSLCOMPLEX *) _object)  -- in c_complex.h
> >
> > to get a pointer to the current object of type GSLCOMPLEX.
> >
> > Next I use:
> >
> > THIS->number.real;
> >
> > to access the value stored in the real member of the number structure.
> > The number structure is a member of the GSLCOMPLEX structure
> >
> > The structures are defined as below:
> >
> > typedef
> >      struct __GSLCOMPLEXNUM
> >      {
> >          double real;
> >          double imagined;
> >      }
> >      GSLCOMPLEXNUM;
> >
> > typedef
> >      struct __GSLCOMPLEX
> >      {
> >          GB_BASE ob;
> >          GSLCOMPLEXNUM number;
> >      }
> >      GSLCOMPLEX;
> >
> > This seems to work when I am simply passing a value to store in the
> > property but causes seg faults when I try to pass the value of
> > THIS->number.real to a function.
> > I know I have missed something very elementary but simply can't see it
> > at this moment... Once you respond I know I will be kicking myself for
> > not seeing it!
> >
> > What I need to do is pass the values stored in GSLCOMPLEX->number.real,
> > and GSLCOMPLEX->number.imagined to c function.
> >
> > My guess is that my method of getting the current object is not working
> > as at times I seem to get a null value for THIS and a value of 0x8 for
> > THIS->number.
> >
> >
> > Thanks for the help!
> >
> >
>
> Please be more precise. Which code does not work exactly?
>
> --
> Benoît Minisini
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Gambas-devel mailing list
> Gambas-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-devel
>



-- 
If you ask me if it can be done. The answer is YES, it can always be done.
The correct questions however are... What will it cost, and how long will
it take?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20120211/816dbf14/attachment.html>


More information about the Devel mailing list