Simple function declaration gone wrong

So, this is just trying to get pinMode initialisation running on an array and I have no idea why it’s killing itself.

This small function:

void initialisePins (array pinList, int mode) {
  for (ii = 0; ii < sizeof(pinList); ii++) {
  pinMode (pinList[ii], mode);
  }
}

is generating all of this in errors:

Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Uno"

sketch_apr22b:2:21: error: variable or field 'initialisePins' declared void

 void initialisePins (array pinList, int mode) {

                     ^

sketch_apr22b:2:21: error: 'array' was not declared in this scope

sketch_apr22b:2:36: error: expected primary-expression before 'int'

 void initialisePins (array pinList, int mode) {

                                    ^

sketch_apr22b:2:22: error: variable or field 'initialisePins' declared void

 void initialisePins (array pinList, int mode) {

                      ^

sketch_apr22b:2:22: error: 'array' was not declared in this scope

sketch_apr22b:2:37: error: expected primary-expression before 'int'

 void initialisePins (array pinList, int mode) {

                                     ^

exit status 1
variable or field 'initialisePins' declared void

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

please send help and/or a blade for me to commit seppuku with.

Please read the forum guide before posting again. Well done for using code tags, but you should always post your full code. Also error messages should be posted inside code tags, not quotation tags.

Without seeing your full code, I am guessing about this, but…

Unless your have defined it elsewhere, and I’m pretty sure you haven’t, “array” is not a keyword in C language.

When you pass an array to a function, that function cannot find the size of the array, so you need to pass the size as another parameter.

Also, sizeof() gives the size in bytes, and int is 2 bytes long on most Arduino.

void initialisePins (byte pinList[], byte pinListLength, int mode) {
  for (ii = 0; ii < pinListLength; ii++) {
    pinMode (pinList[ii], mode);
  }
}

PaulRB:
Please read the forum guide before posting again. Well done for using code tags, but you should always post your full code. Also error messages should be posted inside code tags, not quotation tags.

Without seeing your full code, I am guessing about this, but…

Unless your have defined it elsewhere, and I’m pretty sure you haven’t, “array” is not a keyword in C language.

When you pass an array to a function, that function cannot find the size of the array, so you need to pass the size as another parameter.

Also, sizeof() gives the size in bytes, and int is 2 bytes long on most Arduino.

void initialisePins (byte pinList[], byte pinListLength, int mode) {

for (ii = 0; ii < pinListLength; ii++) {
    pinMode (pinList[ii], mode);
  }
}

Sorry for the post style errors, but I’d actually isolated the function in a separate sketch to play around with (thus the default name) so this was technically the whole code.

I’d figured that as Arduino defines the array data structure that I’d be able to pass it to the function directly (which was very wrong). It’s been fixed up as a pointer now, and once the sizeof() stuff is dealt with it should be functional. Thank you very much for your help!

Please do not quote entire posts, it just makes the thread longer without adding anything. If you have a question about something specific, just quote that part. Otherwise use Reply, not Quote.

I’d actually isolated the function in a separate sketch to play around with (thus the default name) so this was technically the whole code.

No, technically it wasn’t. Won’t compile in isolation. Please remember forum members are not psychic, we cannot see what you see, know what you know, unless you provide the full picture. For example what did you mean by “default name”?