here's a simple and short code I've been trying to run:
#include <stdio.h>
int const SIZE = 5;
void a(int *arr);
int main(){
int arr[5] = {1,2,3,4,5};
a(arr);
return 0;
}
void a(int *arr){
int *i;
for (i=arr; i<&a[5]; i++)
printf("%d",*arr[i]);
}
and i get the following errors/warnings:
main.c: In function ‘main’:
main.c:15: error: variable-sized object may not be initialized
main.c:15: warning: excess elements in array initializer
main.c:15: warning: (near initialization for ‘arr’)
main.c:15: warning: excess elements in array initializer
main.c:15: warning: (near initialization for ‘arr’)
main.c:15: warning: excess elements in array initializer
main.c:15: warning: (near initialization for ‘arr’)
main.c:15: warning: excess elements in array initializer
main.c:15: warning: (near initialization for ‘arr’)
main.c:15: warning: excess elements in array initializer
main.c:15: warning: (near initialization for ‘arr’)
main.c: In function ‘a’:
main.c:22: error: subscripted value is neither array nor pointer
main.c:23: error: array subscript is not an integer
the warning are all associated with the initialization of the array: if I put '5' instead of 'SIZE' its ok, why? The errors in a I don't get at all. I'm passing a pointer as an arguments, where's the problem? thatnks!