Passing an array to a function

Just starting out? Need help? Post your questions and find answers here.
peter
New User
New User
Posts: 8
Joined: Thu Apr 08, 2004 7:56 pm

Passing an array to a function

Post by peter »

I was wondering if I can pass an array to a function.
And the function must return an array.
For example I want to make a outproduct or dotproduct function

So

procedure outproduct(vecta(3),vectb(3))
code
return vect(c)
endprocedure

This doesn't work of course, but how can I do this easily?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Structure whatever
b.b
EndStructure

Procedure aha(*a.whatever, *b.whatever)
*b\b = *a\b
EndProcedure

x.whatever
y.whatever

x\b = 5
aha(@x,@y)
Debug y\b
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Passing an array to a function

Post by traumatic »

peter wrote: procedure outproduct(vecta(3),vectb(3))
code
return vect(c)
endprocedure
I'd do it with structures...

Code: Select all

Structure VECT
  x.f 
  y.f 
  z.f 
EndStructure 

Procedure outproduct(*va.VECT, *vb.VECT, *out.VECT) 
  code
EndProcedure 
maybe you may also take a look at this:
viewtopic.php?t=9457
Good programmers don't comment their code. It was hard to write, should be hard to read.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Passing an array to a function

Post by traumatic »

ooops, too late... :(
Good programmers don't comment their code. It was hard to write, should be hard to read.
Post Reply