Created
December 24, 2014 11:34
-
-
Save drodriguez/c7cebea1fa5b912250e9 to your computer and use it in GitHub Desktop.
TIL about arrays in signatures in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
int test1(int32_t (*array)[10]) { | |
return 1; | |
} | |
int test2(int32_t (*array)[5]) { | |
return 2; | |
} | |
int main(int argc, char **argv) { | |
int32_t a1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | |
int32_t a2[5] = {0, 1, 2, 3, 4}; | |
test1(&a1); | |
test1(&a2); // warning: incompatible pointer types passing 'int32_t (*)[5]' to parameter of type 'int32_t (*)[10]' | |
test2(&a1); // warning: incompatible pointer types passing 'int32_t (*)[10]' to parameter of type 'int32_t (*)[5]' | |
test2(&a2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment