Qbasicnews.com
What the hell? - 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 the hell? (/thread-9678.html)



What the hell? - wallace - 09-21-2006

By commenting blocks I got an error down to one sub call. So I tried using comment blocks to find the error in the sub. I ended up commenting the entire sub out and it still doesn't run. If I take out the sub call it works. THERE IS NO CODE IN THE SUB! What could cause something like this? If you want to see code I'll post it but I don't think it will matter.


What the hell? - Anonymous - 09-21-2006

Of course it will matter.

Post the code.

Also, what version are you using? The current testing release is .17.


What the hell? - wallace - 09-21-2006

Nevermind, it was a bad pointer. I thought code wouldn't matter because I had commented everything out except for this part.

sub loadskin (s as skin ptr)
loadskin1(s->skin1)

and I forgot to allocate s. Don't you just hate when you spend two days trying to figure out what's wrong then it smacks you in the head?


What the hell? - wallace - 09-21-2006

New question: If I have a sub that allocates memory and I don't want it to allocate something twice (create an orphan,) can I deallocate first?

sub foo (s as sometype ptr)
deallocate s
s = allocate (len(sometype));
end sub

if I send it a blank pointer will the deallocate mess something up? It's basically doing the same as:

dim s as sometype ptr
deallocate s


What the hell? - Anonymous - 09-22-2006

deallocate( 0 ) does nothing, so your example will function normally.

if in doubt, try

Code:
if s then

  deallocate s

end if

"if s" breaks down to "if s <> 0"


What the hell? - Agamemnus - 09-22-2006

Cha0s, have you put me on ignore? Sad


What the hell? - DrV - 09-23-2006

You shouldn't free null pointers. You should also specify "ByRef" explicitly if that's what you want; otherwise, it's not clear to the reader, and it will break when you switch to -lang fb.