BBC BASIC for Windows
Programming >> BBC BASIC language >> How to calculate length of array?
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1337607775

How to calculate length of array?
Post by Endymion on May 21st, 2012, 1:42pm

Sometimes I need to pass arrays by value, not by reference. So, I want to create tool for cloning arrays. My code not work:

Code:
      def proc_CloneArray(Array#(), return ArrayClone#())
      local ArrayLength% = len(Array#()) *| just idea illustration
      dim ArrayClone#(ArrayLength%)
      ArrayClone#() = Array#()
      endproc
 

Re: How to calculate length of array?
Post by admin on May 22nd, 2012, 08:04am

on May 21st, 2012, 1:42pm, Endymion wrote:
Sometimes I need to pass arrays by value, not by reference. So, I want to create tool for cloning arrays.

This code works:

Code:
      DEF PROC_CloneArray(Array#(), RETURN ArrayClone#())
      LOCAL ArrayLength%
      ArrayLength% = DIM(Array#(),1)
      DIM ArrayClone#(ArrayLength%)
      ArrayClone#() = Array#()
      ENDPROC 

Can I recommend that you don't use the *| style of commenting routinely, since that sort of comment is preserved in a compiled EXE and wastes space:

http://bb4w.wikispaces.com/Alternative+comment+styles

Richard.
Re: How to calculate length of array?
Post by Endymion on May 22nd, 2012, 08:51am

on May 22nd, 2012, 08:04am, Richard Russell wrote:
This code works:


Thanks!

Quote:
Can I recommend that you don't use the *| style of commenting routinely, since that sort of comment is preserved in a compiled EXE and wastes space:


OK.