Passing an undeclared array to a function

Hi All,

I'm wondering if it's possible to pass an array that I haven't declared and given a name. I've tried to figure out if it has something to do with it being passed by reference and using pointers, but nothing has worked thus far. My goal is to be able to call a specific function many times successively with a new/undeclared array as a parameter being passed, and I'm hoping I don't have to declare it beforehand (doubling the number of lines of code). If anyone has a solution or tips, I'd love to hear them. Thanks!

Example of what I'm trying:

function({3,6,12,45,67});

This code calls the following:

void function(int array[]) {
     yada yada
}

Thanks again!

I'm wondering if it's possible to pass an array that I haven't declared and given a name.

No.

Is there some way that passing different string constants (which are, after all, arrays) would solve your problem? That is the one workaround I can think of to Paul's correct general rule above.

-br

My goal is to be able to call a specific function many times successively with a new/undeclared array as a parameter being passed

Your goal is to write a C/C++ program using a syntax that isn't supported by the language? Why? What has this got to do with writing a program to solve a particular problem?

I'm hoping I don't have to declare it beforehand (doubling the number of lines of code)

Again, why is this a problem? If it requires a few more lines of code to get the job done, then that is what you have to do.

Pete

Write your function to use int pointer then set that pointer to your array.

You don't -have- to use a declared array if for example you just want to read memory but it would be a bad idea to write just anywhere, and kind of dumb to expect meaningful data where it has not been placed.

pseudocode -- not checked, just to convey idea:

int myarray[ 10 ] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int otherarray[ 20 ]; 

int *data; // can point to int or int array

void myfunction( int *d )
{
  // blah blah blah
}

void setup()
{
  // blah blah blah
}

void loop()
{
  // blah blah blah

  myfunction( myarray );
  myfunction( otherarray );

  // blah blah blah
}

tcone: I'm wondering if it's possible to pass an array that I haven't declared and given a name.

If you mean you want to pass in a literal constant of type array, I haven't tested it in Arduino but the following seems valid:

void myFunc(int v[])
{
}

myFunc((int[]){1,2,3});

If you want to pass in a non-constant array which does not have a symbolic name (does not correspond to a named variable), this is possible too if you provide a pointer value that points to a region of memory of the appropriate size - for this to be useful I suppose the callee would need to know or be told the size of the array.