problem with structure unions

Just starting out? Need help? Post your questions and find answers here.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

problem with structure unions

Post by kinglestat »

Code: Select all

Structure CSTR 
  StructureUnion 
    s.s 
    i.i 
  EndStructureUnion 
EndStructure 
Why this structure does not work anymore with PV45RC1 ?
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
User avatar
STARGÅTE
Addict
Addict
Posts: 2265
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: problem with structure unions

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: problem with structure unions

Post by kinglestat »

it is not the same thing
with , String I would have to use Peeks() to retrieve the string!
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: problem with structure unions

Post 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
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: problem with structure unions

Post 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. :)
I may look like a mule, but I'm not a complete ass.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: problem with structure unions

Post 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
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: problem with structure unions

Post by srod »

Either use a pointer or Netmaestro's code above.
I may look like a mule, but I'm not a complete ass.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: problem with structure unions

Post by kinglestat »

thanks netmaestro
should even have been obvious (to me)
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
Post Reply