what's wrong here? (ooplike) - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html) +--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html) +--- Thread: what's wrong here? (ooplike) (/thread-7033.html) Pages:
1
2
|
what's wrong here? (ooplike) - fsw - 04-23-2005 as soon you start uncomment the me.cubed or me.timesX it crashes... Code: ' what's wrong here? (ooplike) - fsw - 04-23-2005 just found out that if the structure is changed to Code: TYPE OOPLIKE WHY? @vic: if this is a compiler bug could you please provide a new fbc & rtl libs? (chicken/egg problem...) what's wrong here? (ooplike) - Joakim - 04-23-2005 Code: FUNCTION Initialize (byval b as integer) as OOPLIKE ptr A solution could be to allocate it as dynamic memory: Code: function Initialize (byval b as integer) as OOPLike ptr Happy coding! what's wrong here? (ooplike) - marzecTM - 04-23-2005 you could in addition to joakims suggestion write a small garbage collector that keeps track of the memory you allocated and deletes it either at program end, or during program execution time ( though this would need some thinking ). Zire has a simple "garbage collector" afair, go ask IT. what's wrong here? (ooplike) - fsw - 04-23-2005 Thank you both for your reply. Don't have time right now to try it out yet, but if it's a mem dealloc problem, than why does it work if I change the structure? Can't wait to have more time and try it out. what's wrong here? (ooplike) - fsw - 04-23-2005 Code: this = callocate(len(OOPLIKE)) I did some more tests: as long there are the 2 additional variables in the structure, I can add more functions inside the structure (before the 2 additional variables). Strange isn't it ... ... because if it's a matter of: Quote:... return a pointer to a structure that no longe exists (it is deallocated when the function returns, as it is a local variable). than it shouldn't work either way (with additional variables or not). And this code works with no problems with xblite... What am I missing? what's wrong here? (ooplike) - Joakim - 04-23-2005 As I see it, you have a pointer to deallocated memory. This is a great way to spawn hard-to-find bugs, as it'll work sometimes and other times not. I can't tell you why padding the structure makes it work (maybe v1ctor can), but it's NOT a solution to the problem. You should never return a pointer to a local variable. what's wrong here? (ooplike) - lkd85 - 04-23-2005 I had this question awhile ago too. Vic just said do the dynamic allocation or just declare it as a Static variable. Code: Static this As OOPLIKE what's wrong here? (ooplike) - Joakim - 04-23-2005 Then the memory pointed to will change every time you call the function... what's wrong here? (ooplike) - fsw - 04-23-2005 Thanks for the explanation. I figured out why it works on xBlite: xBlite is able to return structures, no pointer needed. Vic, could we get structures as return argument? BTW: Vic, don't hesitate to add your thoughts on this dilemma. |