Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:11 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Array Element as Subroutine Argument

Author Message
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 10:29pm 28 Feb 2021
Copy link to clipboard 
Print this post

I take it that the arguments in the declaration of a subroutine cannot be array elements. Too bad.  

x = 1
y = 1
UnitNormal x,y
print x,y
end

sub UnitNormal u(0),u(1)   ' <==== NOT ALLOWED! DRAT.
  MATH V_NORMALISE u(),u()
end sub

Instead, the subroutine must be
sub UnitNormal n1,n2
  u(0) = n1 : u(1) = n2
  MATH V_NORMALISE u(),u()
  n1 = u(0) : n2 = u(1)
end sub

Is there a simpler way?
Visit Vegipete's *Mite Library for cool programs.
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 533
Posted: 10:57pm 28 Feb 2021
Copy link to clipboard 
Print this post

Can't you use this?

u(0) = 1
u(1) = 1
UnitNormal u()
print u(0), u(1)
end

sub UnitNormal a()
 MATH V_NORMALISE a(), a()
end sub

Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 11:51pm 28 Feb 2021
Copy link to clipboard 
Print this post

Not really, because the actual 'vector' I want to normalize is deep in a multi-dimensional array. A bunch of MATH SLICE and MATH INSERT gets too complicated.

The input would be something like
UnitNormal a(i,3),a(i,4)

Visit Vegipete's *Mite Library for cool programs.
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 504
Posted: 02:28am 01 Mar 2021
Copy link to clipboard 
Print this post

Can you add the array values to variables before assign them to the sub?

dim v1=a(i,3),v2=a(i,4)
UnitNormal v1,v2
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025