Sunday, 15 September 2013

c - Why is [static N] not enforced at compile-time? -


void func (int a [static 10]) {if (a == null) {/ * This branch can be customized with printf ("% d", a [1]); / * Cause UB * /}

However, this means C11 6.7.6.3/7 is defined as meaning , not bound , which means that the function has been called incorrectly, the compiler should not continue diagnosing. In fact, compiler should not cancel , unless it is proven that UB is in all branches, for example:

  int main () (function NULL); // UB int b [9]; Ceremony (b); // UB}  

Why did the standard not make this a single (hence a clinical requirement)?

Secondary Question: Why the still was ignored in the prototype (6.7.6.3/13), rather than being a part of the signature? It seems misleading to allow the prototype to be included in it, but the function body does not, and vice versa.

Because violation can not be detected in time compilation in all cases.

For example, this argument can be an indicator for the initial element of an array allocated from malloc () . The compiler can not normally determine how big an array is, or if the argument is an indicator object, then the compiler can usually find that it is empty.

The main purpose of this feature is not to impose restrictions on the call, but to enable optimization, the compiler can assume that parameter is the initial element of an array of specified length Indicates. In some cases, this could enable better code generation.

But surely the compiler can issue non-fatal warnings for those cases that they can detect. There is no implication in the standard that such warnings should not be issued.


No comments:

Post a Comment