Skip to content

Instantly share code, notes, and snippets.

@5shekel
Last active April 23, 2018 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5shekel/2c096206ffe347059da4aa787784db41 to your computer and use it in GitHub Desktop.
Save 5shekel/2c096206ffe347059da4aa787784db41 to your computer and use it in GitHub Desktop.
//see http://arduino.land/FAQ/content/6/32/en/passing-arrays-to-functions.html#pass-multi-by-pointer
int arr_3Da[1][2][3] {
{
{1, 2, 3},
{4, 5, 6}
}
};
int arr_3Db[2][2][3] {
{
{1, 2, 3},
{4, 5, 6},
},
{
{1, 2, 3},
{4, 5, 6},
}
};
void setup() {
Serial.begin(115200);
Serial.println(sizeof(arr_3Da));
passme_3D(arr_3Da);
//but following will throw error
//passme_3D(arr_3Db);
}
void passme_3D(int (&seq)[1][2][3]) {
Serial.println(sizeof(seq));
}
void loop() {
}
/*
// "magic" of tamplates
template< typename T, size_t N >
void Func( T (&array)[N] ) {
//code here
}
template< typename T, size_t N, size_t X >
void Func( T (&array)[N][X] ) {
//Code here
}
template< typename T, size_t N, size_t X, size_t Y >
void Func( T (&array)[N][X][Y] ) {
//Code here
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment