In the following example, is there a way to raise a compilation error when a pointer is used instead of an array?
#include <stdio.h>
static void foo(int tutu[])
{
printf("%d",tutu[2]);
}
int main() {
foo((int[]){1,2,3});//shall display 3 -- displays 3
foo((int*)(int[]){1,2,3});//would be nice to raise a compilation error -- but displays 3
return 0;
}
In other terms, How to forbid usage of pointers (which could points to a not allocated space) and force usage of arrays?
In fact, if I add -Werror to the compilation with gcc, I get
error: taking address of temporary array
10 | foo((int[]){1,2,3});
Which is exactly the opposite that I'm looking for...