News for hackers. Stuff that matters.
Re:Some dark corners of C by caf on Saturday March 09, 2013 @09:34AM (#5348466)
The purpose of

  int foo(int x[static 10])
is not to produce a warning - that's just a nice possible side-effect (and only in some cases).

The real purpose is to allow the compiler to optimise the compilation of the foo() function itself, under the assumption that x will always point to the first element of an array of at least 10 elements.

Re:Some dark corners of C by revelation on Saturday March 09, 2013 @10:15AM (#5348569)
What possible optimization would a compiler be able to do, given that arrays are only ever implicit in compiled C?
Re:Some dark corners of C by jedbrown on Saturday March 09, 2013 @12:37PM (#5349005)
If it knows the address is valid, it can use a speculative load. If it knows there are enough entries, it can use a wide load. Without that knowledge, such instructions could trigger SEGV due to an invalid pointer or the wide load spilling over a page boundary.
Re:Some dark corners of C by tsahyt on Saturday March 09, 2013 @10:08AM (#5348549)
At least or exactly 10 elements?
Re:Some dark corners of C by popee on Saturday March 09, 2013 @10:58AM (#5348683)
At least
Re:Some dark corners of C by tsahyt on Saturday March 09, 2013 @03:09PM (#5349468)
Huh, I didn't know that. I just checked the standard and you appear to be correct, so, just for the record:

"... if the keyword static also appears within the [ and ] of the array type derivation, then for each call to the function, the value of the corresponding actual argument shall provide access to the first element of an array with at least as many elements as specified by the size expression."