Arrays within UDT Arrays - Uggh! 
Author Message
 Arrays within UDT Arrays - Uggh!

I am at a my wit's end. I've search PB message forums, deja.com, and web
sites searching for an answer.

Help me please! I am trying to assign values to a UDT array that happens to
have a member which is an array of integers.

Now, I introduced another member as String * 7 and here's where all hits the
fan. Data assigned to the UDT array gets corrupted or something. I even get
GPFs when I try to evaluate a member.

The corruption seems to vary as I change the length of the String member.
It's as if the length of the string is overlapping to the next member(s) in
the UDT.

Are there any WORD or DWORD alignment issues for 16-bit PB?

I've read that arrays within UDTs are not true arrays, but "conveniences".
I've read they need to be treated as "tables". But I could not find how to
treat them as tables.

The code will work in VB but not PB. Can anyone share any words of wisdom?

---------------
Type ARRAY_WITHIN_TYPE
 sString As String * 7
 iArray(9) As Integer
End type

SUB PBDebug () EXPORT
 Dim udtS As ARRAY_WITHIN_TYPE, udtA() As ARRAY_WITHIN_TYPE
 Dim intNA As Integer, intC As Integer

 intNA = 10
 ReDim udtA(intNA - 1) As ARRAY_WITHIN_TYPE

 udtS.sString = "help"
 For intC = 0 to 9
  udtS.iArray(intC) = 10 - intC

 Next 'intC

 intC = 0
 Do While intC < intNA
  udtA(intC) = udtS

  intC = intC + 1
 Loop

END SUB



Sun, 18 Aug 2002 03:00:00 GMT  
 Arrays within UDT Arrays - Uggh!
Kent --

There is a known issue with arrays within TYPES when the structure is LOCAL,
with PB/DLL and PB/CC.  If that is what is biting you here, an easy workaround
would be to use STATIC instead of LOCAL, and initialize the structure (with
nuls) at the top of the SUB or FUNCTION.

This has been discussed on the powerbasic forums several times, and I understand
that it is on the fix list for the next version.

-- Eric



Sun, 18 Aug 2002 03:00:00 GMT  
 Arrays within UDT Arrays - Uggh!
Actually, the problem is with arrays in UDTs that are "Global" and "Static".
Local UDTs work OK as far as I know.

Another programmer brought the subject up on the PB forum and I thoroughly
tested his theories about the problem.

While I can't absolutely prove their is a problem, I have strong enough
evidence from testing that was enough for me to avoid using Arrays within
UDTs.

The work around is actually quite easy, since PB has "excellent" support for
pointers and also moving bytes using Peek$ and Poke$. Change the arrays to a
single fixed length string and then move the data for each item in the array
by using Peek$ and Poke$ and also pointers.

I am sure that if PowerBasic finds enough evidence that it is a problem,
they will fix it in the next version. For me, I am just playing it safe, by
avoiding them, for now.

Chris Boss
Computer Workshop



Quote:
>Kent --

>There is a known issue with arrays within TYPES when the structure is
LOCAL,
>with PB/DLL and PB/CC.  If that is what is biting you here, an easy
workaround
>would be to use STATIC instead of LOCAL, and initialize the structure (with
>nuls) at the top of the SUB or FUNCTION.

>This has been discussed on the PowerBASIC forums several times, and I
understand
>that it is on the fix list for the next version.

>-- Eric



Sun, 18 Aug 2002 03:00:00 GMT  
 Arrays within UDT Arrays - Uggh!

Quote:
> Actually, the problem is with arrays in UDTs that are "Global" and "Static".
> Local UDTs work OK as far as I know.

You're right, I got it backwards. And Kent's original example looks like it is
using LOCALs, so that's probably not his problem.


Mon, 19 Aug 2002 03:00:00 GMT  
 Arrays within UDT Arrays - Uggh!
Thanks Eric.

Quote:
>on the fix list for the next version

My added delimna is that I am restricted to PB/DLL Version 2.0 (16-bit). The
fix to the next version will probably be just the 32-bit compiler.:(


Mon, 19 Aug 2002 03:00:00 GMT  
 Arrays within UDT Arrays - Uggh!
Kent --

Quote:
> Thanks Eric.

Whoa!  You're thanking me for a wrong answer!  Be sure to read the rest of the
responses to your topic.

-- Eric



Mon, 19 Aug 2002 03:00:00 GMT  
 Arrays within UDT Arrays - Uggh!


Quote:
>Kent --

>> Thanks Eric.

>Whoa!  You're thanking me for a wrong answer!  Be sure to read the rest of
the
>responses to your topic.

Whoa! Too few people have the courtesy to say, "thank you" in the first
place. Kent's manners are exemplary; let's not discourage others.

Besides, you deserved a "thank you" for your efforts alone.

MCM



Tue, 20 Aug 2002 03:00:00 GMT  
 Arrays within UDT Arrays - Uggh!
Michael --

Quote:
> Whoa! Too few people have the courtesy to say, "thank you" in the first
> place. Kent's manners are exemplary; let's not discourage others.

> Besides, you deserved a "thank you" for your efforts alone.

I certainly wasn't trying to be rude, I just wanted to make sure Kent wasn't
mislead by my incorrect advice.  In any event...

To Kent:  You're welcome.

To Michael: Thank you for pointing out what could have been perceived as
rudeness, and for acknowledging my efforts to help Kent, and for saying that I
deserved to be thanked.  And thanks in advance for not thanking me for thanking
you.

-- Eric



Thu, 22 Aug 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. An array of records within an array of records (Still a problem)

2. an array of records within an array of records

3. Inserting Arrays within an Array in Tcl...

4. Problems using an array within another array

5. Problem with with Array of U8 to Array of Array of Boolean

6. convert 2d array to 1d array without using shift registers and build array

7. Arrays: Build array in multiple for loops or replace array elements

8. Multidimensional array vs. array of array

9. Question about array ops on arrays of types of arrays of ...(ack)

10. adjustable-array-p, adjust-array and array-destruction

11. Manipulating string elements within arrays

12. Use of local arrays within functions

 

 
Powered by phpBB® Forum Software