structure help

Just starting out? Need help? Post your questions and find answers here.
szerda
User
User
Posts: 12
Joined: Wed Sep 14, 2005 1:57 pm

structure help

Post by szerda »

hi first sorry my bad english

i want creat a structure orelse like this:

Code: Select all

structure barstr
    start.l
    end.l
endstructure

filenum.l
file[filenum]
    name$
    date.l
    barcount.l
    bar.barstr[barcount]
so my question how can i make this
filenum,barcount : alwasy different and value's i will know when i read from file
if it possible to make anyway like structure,array,list ...
pleas help
thanks
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

SZerda,

The problem is that Structures are a static item, the same as constants.

Static items are resolved at compile time. The compiler uses the Structures to resolve all of the addresses, but then uses those addresses in the final executable. This means that the final executable has no knowledge of the structure.

For example, consider the following code:

Code: Select all

#S_Count = 10

Structure t
  s.b[#S_Count]
  t.b[4]
  u.l
EndStructure

Debug SizeOf(t)

Debug OffsetOf(t\u)
The compiler knows at compile time that the offset of u will be 14 because it knows that s is an array of 10 bytes and t is an array of 4.

Variables, on the other hand, are dynamic. They can change value at run time. For this reason you cannot use them when defining a structure.
szerda
User
User
Posts: 12
Joined: Wed Sep 14, 2005 1:57 pm

Post by szerda »

thanks GedB

yes i know the structure is static

so my question: ther is any other way to creat it?

i tried use 2 list: 1 for file, and 1 for bar

Code: Select all

structure filestr 
    name$ 
    date.l
    barcount.l
endstructure

structure barstr 
    start.l 
    end.l 
endstructure

NewList file.filestr
NewList bar.barstr
but how can i make that every file list has an own bar list?
it is possible?

i hope i was clear
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Perhaps make the barlist a pointer to an allocated block of memory, and the memory as big as required for each instance?
@}--`--,-- A rose by any other name ..
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

this should work:

Code: Select all

structure filestr 
    name$ 
    date.l 
    barcount.l 
endstructure 

structure barstr 
    start.l 
    end.l 
endstructure

dim filestrthing.filestr(999) ; well, change it from 999 lol
dim barstrthing.barstr(999)
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

Code: Select all

structure tbarstr 
    start.l 
    end.l 
endstructure 

structure tfilestr 
    name$ 
    date.l 
    barcount.l 
endstructure 

structure alphastr 
    barstr.tbarstr
    filestr.tfilestr
endstructure 

NewList file.alphastr 
I've never tried to put and structure inside the other, but I think it's possible (I've got no PB on this machine to try). Anyway, if you do like that, everytime you create a file there will be fields for barstr and for filestr inside it. :wink:

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
okasvi
Enthusiast
Enthusiast
Posts: 150
Joined: Wed Apr 27, 2005 9:41 pm
Location: Finland

Post by okasvi »

see help file for "Extends" within structures topic...
szerda
User
User
Posts: 12
Joined: Wed Sep 14, 2005 1:57 pm

Post by szerda »

thanks

but how can i make that every fileList has an own barList?
barList in fileList

it is possible?
Sorry my bad English
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Szerda,

Based on what you've told us, probably not.

What exactly are you trying to achieve?
szerda
User
User
Posts: 12
Joined: Wed Sep 14, 2005 1:57 pm

Post by szerda »

i found answer
i use tinman's double_linked_list
thanks everybody
Sorry my bad English
Post Reply