Converting from C to PB

Just starting out? Need help? Post your questions and find answers here.
Philippe-felixer76
User
User
Posts: 57
Joined: Mon Dec 18, 2006 2:02 pm
Location: Holland

Converting from C to PB

Post by Philippe-felixer76 »

Anybody know how to convert this to PB:

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

?
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

foo.l[5*5]
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

Unsigned quad i guess of 5x5 elements.

A quad is 8bytes.
.l is 4..
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Actually UINT8 is defined as unsigned char, so .c (or .b &$FF) would be correct.
Good programmers don't comment their code. It was hard to write, should be hard to read.
Philippe-felixer76
User
User
Posts: 57
Joined: Mon Dec 18, 2006 2:02 pm
Location: Holland

Post 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..
Philippe-felixer76
User
User
Posts: 57
Joined: Mon Dec 18, 2006 2:02 pm
Location: Holland

Post 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
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post 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
Windows 7 & PureBasic 4.4
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post 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...
Good programmers don't comment their code. It was hard to write, should be hard to read.
Philippe-felixer76
User
User
Posts: 57
Joined: Mon Dec 18, 2006 2:02 pm
Location: Holland

Post 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?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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)]
oh... and have a nice day.
Philippe-felixer76
User
User
Posts: 57
Joined: Mon Dec 18, 2006 2:02 pm
Location: Holland

Post 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!
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Philippe-felixer76
User
User
Posts: 57
Joined: Mon Dec 18, 2006 2:02 pm
Location: Holland

:P

Post by Philippe-felixer76 »

:P Was your motivation also to get porting from C to PB easyer?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: :P

Post 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.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Philippe-felixer76
User
User
Posts: 57
Joined: Mon Dec 18, 2006 2:02 pm
Location: Holland

Re: :P

Post 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!
Post Reply