I am new to Arduino, but come from a c++ back ground in microsofts VS. I am trying to pass an array into a function by reference, so that more than one function can operare on the same array. An example of what I'm trying to do:
void function(int &);
void setup(){
Serial.begin(9600);
};
void loop(){
int counter[10];
funtion(&cunter[]);
for(int i=0;i<10;i++){
Serial.println(counter*);*
}* }; void function(int &functionary[]){
for(int i=0;i<10;i++){* funtionary_=(i10);_
_ }_
_}_
_[/quote]*_ At least in VS. this is how I would do it, however arduino returns an error stating 'declaration of 'ary' as array of references'. I'm not really sure what to do as a work around. So far I have concluded that the prototype is needed to fix a bug in arduino's auto-prototyping, and I have found several postings saying you can not return an array from a function. Anything will help. rigg
Thank you Groove i know there are some spelling mistakes in the code. This is just a quick example of my code to clearly demonstrate the problem i was having.
AlphaBata- do the arrays pass by reference because of arduino's auto-prototype thing. Because I tryed just running code very similer to how you have it writen and did not get anything to print to the serial line. Should I leave off the prototype?
Yes I beleive all the input has helped me solve my problem. It is going to be a few days before I can run the code to a microcontroller, however all the compiling errors have gone away. I will let every one know how it turns out in a couple of days.
Thank you to everybody how took time to help out, this is my first time asking for help in a forum and I am very thankfull with the quick responses.
If you have an array of, for instance, intsint x[10];And an array reference likei = x[2];Then the pointer equivalent would bei = *(x + 2);There's no need to multiply by sizeof(int) -- C does this for you automatically.
AIf you have an array of, for instance, intsint x[10];And an array reference likei = x[2];Then the pointer equivalent would bei = *(x + 2);There's no need to multiply by sizeof(int) -- C does this for you automatically.
Ah. True that.
I just came from a C code dealing with void pointers.
:-[