Liste des Groupes | Revenir à cl c |
David Brown <david.brown@hesbynett.no> writes:Certainly compilers are more likely to be able to differentiate between null values and non-null values, than between pointers to different lengths of data. So yes, this can be a useful check.
[...]I am not convinced that it is actually useful as an error checking[...]
mechanism in many situations. In a lot of code, you simply don't have
a compile-time checkable array sizes - you have a pointer, and a
run-time variable for the size. When you are calling your function
with a "static" array size, the compiler does not have any way to
check your pointer for correctness.
Using [static N] in an array parameter declaration also requires the
caller to pass a non-NULL pointer. If I want to tell the compiler
that an argument must not be a NULL pointer, I can write:
void func(int arg[static 1]);
func(NULL) then has undefined behavior, and a compiler is likely
to warn about it. (Of course some UB will be missed if the compiler
can't detect it.)
Les messages affichés proviennent d'usenet.