Why am I not getting any warnings in my third function call? Like one in the second function call).
Is NULL != NULL?
#include <stdio.h>
#include <stdlib.h>
void my_function(int arr[static 1]){
printf("first element: %d\n", *arr);
}
int main(void){
int arr[]={1,2,3};
// FISRST:
//works as expected
my_function(arr);
//SECOND:
//compiler warns as expected
//and a segmentation fault while running
my_function(NULL);
//THIRD:
//no warnings
//and segmentation fault
int* p=NULL;
my_function(p);
return EXIT_SUCCESS;
}
or another example:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
void my_function(int arr[static 5]){
printf("first element: %d\n", *arr);
}
int main(void){
int arr[]={1,2,3};
//FIRST
//a compiler warning
//(array argument is too small)
my_function(arr);
//SECOND
//no warnings
int* p=arr;
my_function(p);
return EXIT_SUCCESS;
}
The second function call has a pointer to the same location as the first function call. It seems that this feature doesn't work with pointers.
int foo(void) { int a[3]; return a[4]; }with Apple Clang 11.0.0 report “ warning: array index 4 is past the end of the array (which contains 3 elements)”?