1

In the source code for the xv6 operating system, there is the following array declaration:

static uint64 (*syscalls[])(void) = {
[SYS_fork]    sys_fork,
[SYS_exit]    sys_exit,
[SYS_wait]    sys_wait,
...
};

What values in the brackets are macros defined in a header file, but what do the brackets here mean?

Ian_L
  • 93
  • 4
  • 1
    @Exampleperson It's an array of function pointers (to functions of type `uint64(void)`). – user17732522 Feb 08 '22 at 17:56
  • 3
    Note that the standard C syntax requires `=` after the square brackets, e.g. `[SYS_fork] = sys_fork,`. GCC allows the `=` to be omitted because it used that syntax before the proper syntax was standardized by C99. – Ian Abbott Feb 08 '22 at 17:56
  • @IanAbbott I wonder why they did not adopt this syntax. It is unambiguous and looks cleaner. Could be opinionated though – Eugene Sh. Feb 08 '22 at 18:00
  • 1
    @EugeneSh. I suppose it was for consistency with structure member designations. – Ian Abbott Feb 08 '22 at 18:06

0 Answers0