BBC BASIC for Windows
« Passing substructure arrays to procedures »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:46pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Passing substructure arrays to procedures  (Read 624 times)
Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Passing substructure arrays to procedures
« Thread started on: Jul 12th, 2013, 06:24am »

Hi,

In Wiki there is a section on passing substructures to procedures. In my program I want to copy an array from a structure rather than a substructure.

I've tried the following:
Code:
      DIM a{b(3)}, c(3)
      FOR I = 0 TO 3
        a.b(I) = I * 10
      NEXT
      PROC_TEST(a{}, a.b(), c())
      END
      
      DEF PROC_TEST(x{}, y(), RETURN z())
      !(^y()+4) += !(^x{}+4)
      FOR I = 0 TO 3
        z(I) = y(I)
      NEXT
      ENDPROC
 

However, I get a bad subscript error before going to the PROC (line 4).

Is there a way of doing this?

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Passing substructure arrays to procedures
« Reply #1 on: Jul 12th, 2013, 07:51am »

on Jul 12th, 2013, 06:24am, Matt wrote:
In my program I want to copy an array from a structure rather than a substructure.

Since substructures aren't involved at all, there's no complication and you don't need to take any special measures:

Code:
      DIM a{b(3)}, c(3)
      FOR I = 0 TO 3
        a.b(I) = I * 10
      NEXT
      PROC_TEST(a{}, c())
      END

      DEF PROC_TEST(x{}, z())
      LOCAL i
      FOR i = 0 TO 3
        z(i) = x.b(i)
      NEXT
      ENDPROC 


Richard.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: Passing substructure arrays to procedures
« Reply #2 on: Jul 13th, 2013, 05:48am »

OK. That's useful to know. However, maybe I wasn't quite clear on what I want. Let me adjust the code slightly to elucidate.
Code:
      DIM a{b(3), d(3)}, c(3)
      FOR I = 0 TO 3
        a.b(I) = I * 10
      NEXT
      PROC_TEST(a.b(), c())
      ...
      REM do something with c()
      ...
      PROC_TEST(a.d(), c())
      ...
      REM do something with c()
      ...
      END

      DEF PROC_TEST(x(), z())
      LOCAL i
      FOR i = 0 TO 3
        z(i) = x(i)
      NEXT
      ENDPROC 


This won't work (obviously, otherwise I wouldn't be asking the question), but I hope you get the idea.

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Passing substructure arrays to procedures
« Reply #3 on: Jul 13th, 2013, 09:13am »

on Jul 13th, 2013, 05:48am, Matt wrote:
This won't work

The syntax a.b() is not valid in BBC BASIC; there is no way of representing a 'whole array' when it is a structure member. This is what it says in the BB4W Help: "Normally a structure member can be treated in exactly the same way as a simple variable of the same type. However this is not so in the case of operations on entire arrays or entire structures which cannot be used with structure members":

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin2.html#members

It is, I would suggest, quite unusual to want to be able to perform the same operation on two different structure members (such as your a.b array and your a.d array). If the two arrays are sufficiently 'compatible' in their format and their usage that it is meaningful to perform the same operation, could you not combine them into a single two-dimensional array:

Code:
      DIM a{b(3,1)}, c(3)
      FOR I = 0 TO 3
        a.b(I,0) = I * 10
        a.b(I,1) = I * 11
      NEXT
      PROC_TEST(a{}, 0, c())
      
      REM do something with c()
      
      PROC_TEST(a{}, 1, c())
      
      REM do something with c()
      
      END
      
      DEF PROC_TEST(x{}, j, z())
      LOCAL i
      FOR i = 0 TO 3
        z(i) = x.b(i,j)
      NEXT
      ENDPROC 

Richard.
« Last Edit: Jul 13th, 2013, 09:15am by admin » User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: Passing substructure arrays to procedures
« Reply #4 on: Jul 13th, 2013, 1:21pm »

on Jul 13th, 2013, 09:13am, Richard Russell wrote:
It is, I would suggest, quite unusual to want to be able to perform the same operation on two different structure members (such as your a.b array and your a.d array).

I would normally agrre with you.

Quote:
If the two arrays are sufficiently 'compatible' in their format and their usage that it is meaningful to perform the same operation, could you not combine them into a single two-dimensional array.


I could do that, but I used seperate arrays due to naming. I'll have to use the code that I have been using, which is seperating them using CASE OF.

Thanks.

Matt
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls