Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It also only works with that order, not if the size is after the array :(


No, you can predeclare the size; this compiles with no warnings:

    #include <string.h>
    #include <unistd.h>

    void foo(size_t n; const char s[static n], size_t n)
    {
      write(1, s, n);
    }

    int main(int argc, char **argv)
    {
      foo("hello, ", 7);
      if (argc > 1) foo(argv[1], strlen(argv[1]));
      foo("\n", 1);
      return 0;
    }
However, it still compiles with no warnings if you change 7 to 10!

Clang does not support this syntax.


It does warn: https://godbolt.org/z/Gj54f8313

It did not in GCC 13, but I fixed this bug.


Thank you very much! I tested with GCC 12.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: