C structures & equivilent in PB

Everything else that doesn't fall into one of the other PB categories.
MrTATaod
User
User
Posts: 20
Joined: Wed Jun 28, 2006 6:11 pm

C structures & equivilent in PB

Post by MrTATaod »

Hello

In C I've got a array of structures, defined like this :

Code: Select all

struct {
  char *fileName;
  int fD;
  } example

struct example files[]={
  "1.dta",1
  "2.dta",2
   };
etc. Whilst I've defined the PB structure using

Code: Select all

structure example
   fileName.s
   fd.l
enstructure
and dimmed and array to hold the fields, I do have one problem : When passing the array to a C DLL, I've found that the alignment is all wrong, and that the contents of file[1] is taken from further down the array (around files[8] or so).

Is there any way I can get to the two to exactly align ?
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

You need to use a StaticArray, which is only available within structures:

Code: Select all

Structure example
   fileName.s
   fd.l
EndStructure

Structure exampleArray
  item.example[2]
EndStructure

ea.exampleArray
With ea\item[0]
  \fileName="1.dta"
  \fd=1
EndWith
With ea\item[1]
  \fileName="2.dta"
  \fd=2
EndWith

I know this is a little clumsy, but I think the idea is that it provides the advanced developer with the C compatability without cluttering the core language for the beginner.
MrTATaod
User
User
Posts: 20
Joined: Wed Jun 28, 2006 6:11 pm

Post by MrTATaod »

Thanks - I'll have to try that.

Yes. Thats fine.
Post Reply