Converting from C to PB
Posted: Tue Jun 26, 2007 6:53 am
Anybody know how to convert this to PB:
struct something
{
uint8 year[5][5]
}
?
struct something
{
uint8 year[5][5]
}
?
http://www.purebasic.com
https://www.purebasic.fr/english/
Thats a bit smart .. but you will get into troubleInner wrote:foo.l[5*5]
Tnx for the reply, you PB freakstraumatic wrote:Actually UINT8 is defined as unsigned char, so .c (or .b &$FF) would be correct.
Use:Philippe-felixer76 wrote:Why isn't it possible to use dim foo.l(5,5) in a structure..
Code: Select all
Structure foo
bar.l[5]
EndStructure
Multidimensional arrays in structures aren't supported (by now).Philippe-felixer76 wrote:Why isn't it possible to use dim foo.l(5,5) in a structure..
Code: Select all
Structure something_
a.c[5]
EndStructure
Structure something
b.something_[5]
EndStructure
This is interesting, i was thinking this way also, using a substructure...traumatic wrote:Multidimensional arrays in structures aren't supported (by now).Philippe-felixer76 wrote:Why isn't it possible to use dim foo.l(5,5) in a structure..
You could however work around this limitation something like this:Yes, ugly, I know...Code: Select all
Structure something_ a.c[5] EndStructure Structure something b.something_[5] EndStructure
Code: Select all
Macro BiCoord5( BCRow, BCLine )
( 5 * BCLine + BCRow )
EndMacro
Structure Puit
Narf.c[25]
EndStructure
Define Fjord.Puit
Fjord\Narf[BiCoord5(2,3)] = 42
Debug Fjord\Narf[BiCoord5(2,3)]
YES, Great solution! Tnx!Kaeru Gaman wrote:why not use a linear array in the struct and calculate line and row, e.g. by a Macro?
Code: Select all
Macro BiCoord5( BCRow, BCLine ) ( 5 * BCLine + BCRow ) EndMacro Structure Puit Narf.c[25] EndStructure Define Fjord.Puit Fjord\Narf[BiCoord5(2,3)] = 42 Debug Fjord\Narf[BiCoord5(2,3)]
Psychophanta wrote:http://www.purebasic.fr/english/viewtopic.php?t=15752
:roll:
Not really, i just saw it is useful.Philippe-felixer76 wrote:Was your motivation also to get porting from C to PB easyer?
Thats a fact!Psychophanta wrote:Not really, i just saw it is useful.Philippe-felixer76 wrote:Was your motivation also to get porting from C to PB easyer?