Page 1 of 1

problem with structure unions

Posted: Fri Jul 23, 2010 2:21 pm
by kinglestat

Code: Select all

Structure CSTR 
  StructureUnion 
    s.s 
    i.i 
  EndStructureUnion 
EndStructure 
Why this structure does not work anymore with PV45RC1 ?

Re: problem with structure unions

Posted: Fri Jul 23, 2010 2:32 pm
by STARGÅTE
Structure clear because this structure can not be totally deleted, because it is not clear whether an integer is filled or the string.
So it would come to a memory leak.
Use a this or fixstrings:

Code: Select all

Structure CSTR 
  StructureUnion 
    s.String
    i.i 
  EndStructureUnion 
EndStructure

Re: problem with structure unions

Posted: Fri Jul 23, 2010 4:14 pm
by kinglestat
it is not the same thing
with , String I would have to use Peeks() to retrieve the string!

Re: problem with structure unions

Posted: Fri Jul 23, 2010 4:51 pm
by netmaestro
with , String I would have to use Peeks() to retrieve the string!

You would just drill down one more level:

Code: Select all

Structure dog
  StructureUnion
    name.string
    i.i 
  EndStructureUnion
EndStructure

With puppy.dog
  \name\s = "Bowser"
EndWith

Debug puppy\name\s

Re: problem with structure unions

Posted: Fri Jul 23, 2010 5:52 pm
by srod
@Kinglestat : even allowing for the fact that earlier versions of PB permitted you to do such a thing, it would never have been a good idea because of the reasons STARGÅTE outlined. You are just asking for trouble, especially if using this structure in the form of a local variable. I'd expect some serious crashes here when PB's generated code attempted to tidy up the stack etc. :)

Re: problem with structure unions

Posted: Sat Jul 24, 2010 8:00 am
by kinglestat
the problem is speed; I need to quickly have access to a string in a particular memory location without using Peeks()
If you have any ideas, please feel free to share

cheers

Re: problem with structure unions

Posted: Sat Jul 24, 2010 9:53 am
by srod
Either use a pointer or Netmaestro's code above.

Re: problem with structure unions

Posted: Mon Jul 26, 2010 12:10 pm
by kinglestat
thanks netmaestro
should even have been obvious (to me)