BYREF arrays

Questions about the BASICtools and MakeItC
Post Reply
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

BYREF arrays

Post by YahooArchive »

Hi Bruce,

Does the compiler support passing a pointer to an integer array?

such as:

#define ARRAYSIZE 10

dim array(ARRAYSIZE) as integer


FUNCTION findSum(BYREF array)
dim sum as integer
dim i as integer

for i=0 to ARRAYSIZE
sum = sum + array(i)
next

return (sum)

END FUNCTION

main:

dim i as integer

for i=0 to ARRAYSIZE
array(i) = i
next i

print findSum(array)

end



YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: BYREF arrays

Post by YahooArchive »

No the compiler only supports BYREF passing of a STRING or BYTE array at
present.

But you can accomplish the same thing by passing ADDRESSOF array, and then use
pointers to read or write elements

sub x(addr, offset)
dim x
x = *(addr + (offset<<2))
*(addr + (offset<<2)) = x
end sub

main:
dim a(20)

x(addressof a, 3)

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: BYREF arrays

Post by YahooArchive »

Cool! Thanks Bruce!

Post Reply