1
void string_sort_quick(size_t size, char *array[static size])
{
    string_sort(0, size - 1, array);
}

What exactly does static size promise here? That there will be at least size pointers to char arrays; or that the pointers will point to char arrays of at least size length? Does static in this context concern row or column?

Assuming it does concern columns (length of char arrays) – is there any way to express that there will be size pointers?


Edit/Answer

As DavidRanieri pointed out in the comments, it is to be understood as "At least size pointers to char arrays." Compiling with Clang supports this, as

static void func(char *array[static 2])
{
    printf("%s\n", array[0]);
}

int main(void)
{
    char *arr1[] = {"abc"};
    func(arr1);

    return 0;
}

will inform you that the array argument is too small; contains 1 elements, callee requires at least 2. (GCC is silent about this, see GCC : Static array index in function argument doesn't trigger any warning).

Take note that static void func(size_t size, char *array[static size]) is a bad idea. Clang won't accept it, telling you that a parameter is not allowed. GCC does not tell you what it thinks about any of it.

  • 1
    At least size pointers to char arrays. You can read it as "at least size elements of the type" – David Ranieri Feb 18 '21 at 17:36
  • 1
    @DavidRanieri Nice, thank you! Any idea where this is documented? (Ah, your edit made it clearer, ty!) – Jonas M. Schlatter Feb 18 '21 at 17:38
  • 1
    C11 6.7.6.3/7 _A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’, where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. 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._ – David Ranieri Feb 18 '21 at 17:40
  • 1
    `gcc` doesn't check for this feature, `clang` raises a warning when you use few elements https://godbolt.org/z/9s78zj – David Ranieri Feb 18 '21 at 18:00
  • 1
    Outstanding! I just got clang running on my machine to do that exact same test... didn't know about that website. Thanks a bunch! (: – Jonas M. Schlatter Feb 18 '21 at 18:22
  • yeah! is a wonderful site!!! – David Ranieri Feb 18 '21 at 18:24

0 Answers0