Static keyword in function parameter with an array of pointers? [duplicate]

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 silently ignores it and no longer warns about the array argument being to small. MSVC won't accept it, telling you that a parameter is not allowed. GCC does not tell you what it thinks about any of it.



Read more here: https://stackoverflow.com/questions/66264998/static-keyword-in-function-parameter-with-an-array-of-pointers

Content Attribution

This content was originally published by Jonas M. Schlatter at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: