Page 1 of 2

Converting from C to PB

Posted: Tue Jun 26, 2007 6:53 am
by Philippe-felixer76
Anybody know how to convert this to PB:

struct something
{
uint8 year[5][5]
}

?

Posted: Tue Jun 26, 2007 8:52 am
by Inner
foo.l[5*5]

Posted: Tue Jun 26, 2007 9:49 am
by Edwin Knoppert
Unsigned quad i guess of 5x5 elements.

A quad is 8bytes.
.l is 4..

Posted: Tue Jun 26, 2007 10:06 am
by traumatic
Actually UINT8 is defined as unsigned char, so .c (or .b &$FF) would be correct.

Posted: Tue Jun 26, 2007 11:56 am
by Philippe-felixer76
Inner wrote:foo.l[5*5]
Thats a bit smart .. but you will get into trouble
later on using functions from the DLL..

uint8 is a byte i believe.

Why isn't it possible to use dim foo.l(5,5) in a structure..

Posted: Tue Jun 26, 2007 11:58 am
by Philippe-felixer76
traumatic wrote:Actually UINT8 is defined as unsigned char, so .c (or .b &$FF) would be correct.
Tnx for the reply, you PB freaks :P

Posted: Tue Jun 26, 2007 12:04 pm
by milan1612
Philippe-felixer76 wrote:Why isn't it possible to use dim foo.l(5,5) in a structure..
Use:

Code: Select all

Structure foo
  bar.l[5]
EndStructure

Posted: Tue Jun 26, 2007 1:03 pm
by traumatic
Philippe-felixer76 wrote:Why isn't it possible to use dim foo.l(5,5) in a structure..
Multidimensional arrays in structures aren't supported (by now).


You could however work around this limitation something like this:

Code: Select all

Structure something_
  a.c[5]
EndStructure

Structure something
  b.something_[5]
EndStructure
Yes, ugly, I know...

Posted: Tue Jun 26, 2007 3:49 pm
by Philippe-felixer76
traumatic wrote:
Philippe-felixer76 wrote:Why isn't it possible to use dim foo.l(5,5) in a structure..
Multidimensional arrays in structures aren't supported (by now).


You could however work around this limitation something like this:

Code: Select all

Structure something_
  a.c[5]
EndStructure

Structure something
  b.something_[5]
EndStructure
Yes, ugly, I know...
This is interesting, i was thinking this way also, using a substructure...

You say 'By now', can't some of the core devels
tell/post something about this? Something about
support planned in very near future?

Posted: Tue Jun 26, 2007 4:33 pm
by Kaeru Gaman
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)]

Posted: Tue Jun 26, 2007 5:09 pm
by Philippe-felixer76
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)]
YES, Great solution! Tnx!

Posted: Tue Jun 26, 2007 7:45 pm
by Psychophanta

:P

Posted: Tue Jun 26, 2007 8:08 pm
by Philippe-felixer76
:P Was your motivation also to get porting from C to PB easyer?

Re: :P

Posted: Tue Jun 26, 2007 8:25 pm
by Psychophanta
Philippe-felixer76 wrote::P Was your motivation also to get porting from C to PB easyer?
Not really, i just saw it is useful.

Re: :P

Posted: Tue Jun 26, 2007 8:57 pm
by Philippe-felixer76
Psychophanta wrote:
Philippe-felixer76 wrote::P Was your motivation also to get porting from C to PB easyer?
Not really, i just saw it is useful.
Thats a fact! :P

It also makes porting C headers a lot easy'er,
and makes adding purebasic user libs easy'er,
and makes purebasic more and more powerfull,
and makes all purebasic users and developpers very happy.
and makes purebasic a more complete product,
and makes the world a better place!