Best way to point to arrays of various sizes?

What could be included in further releases, or for the forum.
Post Reply
Nutsy
Posts: 237
Joined: Sun Jul 24, 2016 4:26 pm

Best way to point to arrays of various sizes?

Post by Nutsy » Fri Mar 24, 2017 1:22 pm

Right I have a 2 mean functions to average out sets of samples across arrays... but only 1 version works... Need some help with that.

https://hastebin.com/ofodolaguw.m

The first one works, the array size declaration in the function [sampleAmount] is a macro define... And works. But if i was to change that to a const variable it no longer works.

The first one is ok... because its used by most of the arrays that are constantly reading data... RPM Speed Volts Fuel and such...

The second version of the find_mean function is for the few arrays that might have different array sizes...

But like the first one, it cane take actual variables.

What am I doing wrong and how do I fix it?

Any help please :)

Thanks

User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Best way to point to arrays of various sizes?

Post by BennehBoy » Fri Mar 24, 2017 1:47 pm

unsigned long find_mean(int sampleNum, unsigned long *sampleSet)
-------------------------------------
https://github.com/BennehBoy

Nutsy
Posts: 237
Joined: Sun Jul 24, 2016 4:26 pm

Re: Best way to point to arrays of various sizes?

Post by Nutsy » Fri Mar 24, 2017 1:57 pm

BennehBoy wrote:unsigned long find_mean(int sampleNum, unsigned long *sampleSet)
Sadly that hasnt worked either :/ still getting

Invalid arguments '
Candidates are:
unsigned long int find_mean(unsigned long int (&)[20])
unsigned long int find_mean(int, unsigned long int *)
unsigned long int find_mean(unsigned long int (&)[20])
unsigned long int find_mean(unsigned long int (&)[])
'

User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Best way to point to arrays of various sizes?

Post by BennehBoy » Fri Mar 24, 2017 2:07 pm

That's because you're defining your array as type int

Code: Select all

int samples[100]; array size is defined
just change the function definition accordingly....

unsigned long find_mean(int sampleNum, int *sampleSet)
-------------------------------------
https://github.com/BennehBoy

Nutsy
Posts: 237
Joined: Sun Jul 24, 2016 4:26 pm

Re: Best way to point to arrays of various sizes?

Post by Nutsy » Fri Mar 24, 2017 2:35 pm

oohhhh

thanks...

Silly me... Still you would think that somewhere in the backend of c that an int would be accepted in a long equation... its only a number and the number is well within the limits of long... :p

I guess I could write some type converting in the declaration but cba at the moment... and not really sure how :p

zmemw16
Posts: 1369
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Best way to point to arrays of various sizes?

Post by zmemw16 » Fri Mar 24, 2017 9:26 pm

pretty sure i've seen this done with 'templates' that work on any type of arg ?

well past me in c++ just noted it as a maybe useful at the time

stephen

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests