News for hackers. Stuff that matters.
Re:Linus on compiler warnings and code reviews by mortehu on Wednesday September 23, 2015 @04:26PM (#10267905)
This is one of the many uses of the static keyword in C99:

  void ten(char foo[static 10]) { }

  void generates_warning() {
    char foo[3];
    ten(foo);
  }
This causes clang to emit the following warning:

> warning: array argument is too small; contains 3 elements, callee requires at least 10

Re:Linus on compiler warnings and code reviews by merlincorey on Wednesday September 23, 2015 @04:43PM (#10268038)
The warning is true - it is "at least" 10:

    char ten(char foo[static 10]);

    char ten(char foo[static 10]) { return foo[1]; }

    void generates_no_warning(void);

    void generates_no_warning() {
        char foo[30];
        ten(foo);
    }

    int main() {
        generates_no_warning();
    }
Modified also so it would build cleanly with -Weverything -Werror
Re:Linus on compiler warnings and code reviews by uxcn on Wednesday September 23, 2015 @05:15PM (#10268287)
It avoids stepping on memory elsewhere in the program though. My personal preference for C99 and above is to pass the length as a parameter.

    int do_stuff(size_t len, int64_t arr[len]);
It still suffers from the pointer decay problem, but it at least forces whoever is reading/writing the code to acknowledge the length.
Re:Linus on compiler warnings and code reviews by uxcn on Wednesday September 23, 2015 @05:27PM (#10268363)
How does that parse? I thought static was only a storage class.
Re:Linus on compiler warnings and code reviews by syncsynchalt on Wednesday September 23, 2015 @05:51PM (#10268504)
When extending the language, the committee will often try to re-use existing reserved keywords to avoid colliding with a variable name in someone's code.

Thus we have yet another overloading of "static" in C, the use of "auto" in C++11 (which worked out quite well), and interesting type names such as "long long" in both.

When the committee breaks this rule (think nullptr in C++11) they first must choose a name which is suitably rare (and often a bit clunky as a result), they then scan for that name in large code corpuses, and evaluate how much work they are making for the maintainers of any codebase that's going to be compiled against a new compiler (and which may need to be modified to do so).

Some languages (I'm thinking JS specifically) have keywords that are not in use but are still reserved in case they may be useful in the future.