0

I have just been looking at some documentation for the recv function call, which is available here.

The API is specified as

ssize_t recv(int sockfd, void buf[.size], size_t size, int flags);

I have not seen this syntax before: void buf[.size].

This looks like an array, void buf[], which I would guess is effectively the same as void*.

However, what is the .size object? This looks like a parameter for the length of the array.

It sort of suggests that the compiler might produce one version of recv for each static length .size. But this doesn't really make any sense and I can't imagine this is what the compiler is actually doing, since recv is a library function, part of the Linux sockets library (which is already compiled, the compiler just links against it).

2
  • @TobySpeight what is your logic? How could I have possibly found the answer by searching for totally different functions? Commented Feb 22 at 17:21
  • 2
    Nobody is saying you should have done that. Marking questions as duplicate allows future readers to find the same good answers via either question. It's certainly not a criticism of you! Commented Feb 22 at 17:30

1 Answer 1

4

It's the syntax adopted by the Linux Manual Pages project to indicate that the buffer's size is described by the size parameter of the same function call.

Edit: Found the other StackOverflow thread with more detailed discussion: Linux memcpy restrict keyword syntax

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.