I know that the restrict qualifier in C specifies that the memory region pointed by two pointers should not overlap. It was my understanding that the Linux (not SUS) prototype for memcpy looks like -
void* memcpy(void *restrict dest, const void *restrict src, size_t count);
However, when I looked at man7.org/memcpy it seems that the declarations is -
void *memcpy(void dest[restrict .n], const void src[restrict .n], size_t n);
My questions are -
- When did this syntax get introduced? C99 or later or is this some GNU extension?
- What does the
.beforensignify? I am familiar with the variable length array declaration. Is the.for the variable appearing after the array specification? Is this part of the standard?
TLDR: It's an ad hoc syntax created in a discussion in a Linux mailing list that is used to express the size of VLA before the variable is declared, the
.in.nmeansnrefers to a parameter in the current function declaration, butnmay appear after the currently declared parameter. They have also extended the usualint a[restrict n]parameter declaration tovoidtype. I have no idea where such syntax can be found in the official documentation, but the mailing list has all the details.The change to the
memcpysyntax in the Linux library functions manual was introduced by commit c64cd13e. The commit message is copied here verbatim for reference.Admittedly, it is weird enough from the C language perspective, because while
void f(int n, int[restrict n])is valid VLA syntax,void f(int n, void[restrict n])is not because we are not allowed to have arrays ofvoid.For the
.beforen, if we dig deeper we can find this thread from thelinux-manmailing list.According to my understanding, this basically means the
.is a way to refer to a VLA array size parameter that is used before declaration, and one use case is to handle mutual references.There is a follow-up thread that states,
Of course, there was also objection, which I think many people in the SO community would agree with,