为什么 Linux NETLINK 手册页提供 C++ 示例而不提供 C?
Why does Linux NETLINK man page provide C++ examples but not C?
我处理了 netlink API and examine its man pages netlink(3) and netlink(7)。
突然遇到这样的构造:
struct msghdr msg;
msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
我在 C 中尝试过,但出现错误:
error: expected expression before ‘{’ token
好像是c++(不知道是什么标准)
当然很明显 Netlink 是一个 API 并且没有特定的语言绑定。但这是 C 实现,我看到的关于 C API 的所有 MAN 页面都有纯 C 示例。为什么没有关于示例中使用的语言的注释?这种做法是为了什么,为什么不是 f.e。在 Python 或其他什么?
UPD:我认为这不是 MAN 页面中的拼写错误或无意错误。还有一些其他地方使用此 C++ 功能,例如:
struct iovec iov = { buf, sizeof(buf) };
struct sockaddr_nl sa;
struct msghdr msg;
struct nlmsghdr *nh;
msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
len = recvmsg(fd, &msg, 0);
for (nh = (struct nlmsghdr *) buf; NLMSG_OK (nh, len);
nh = NLMSG_NEXT (nh, len)) {
...
看来是有意识地选择了 C++。
Why does Linux man page provides C++ examples but not C?
Linux 手册页提供了 C 示例。他们不提供 C++ 示例。
I tried it in C, but it gives the error:
这是文档中的一个错误。应该是:
struct msghdr msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
我相信你可以 post 在 linux-man 邮件列表上提交错误报告。
Why there is no note about the language used in examples?
如所述on the project homepage, Linux man pages document the Linux kernel and the C library interface. The Linux kernel is written in C (primarily, there is some assembly, etc.)。因此,Linux 手册页以 C 编程语言提供示例。
What is this practice for and why is this not f.e. on Python or whatever?
惯例是在Linux的开发中使用C语言。它不是 Python 或任何其他语言,因为 Linux 内核是用 C 编程语言编写的。 Linux 内核是用 C 编程语言编写的,因为 Linux 内核的创建者 Linus Torvalds 很久以前就决定用 C 编程语言编写内核。
内核开发人员使用内核本身编写的语言为用户space程序分发内核接口API是最简单的,因此他们不必为用户重写它space 另一种编程语言的程序。它们还可以使用例如 user-space 在内核本身中使用的相同头文件。例如,这可以减少错误和工作量等。因此,内核开发人员最容易使用以 C 编程语言编写的示例来提供文档。
我处理了 netlink API and examine its man pages netlink(3) and netlink(7)。
突然遇到这样的构造:
struct msghdr msg;
msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
我在 C 中尝试过,但出现错误:
error: expected expression before ‘{’ token
好像是c++(不知道是什么标准)
当然很明显 Netlink 是一个 API 并且没有特定的语言绑定。但这是 C 实现,我看到的关于 C API 的所有 MAN 页面都有纯 C 示例。为什么没有关于示例中使用的语言的注释?这种做法是为了什么,为什么不是 f.e。在 Python 或其他什么?
UPD:我认为这不是 MAN 页面中的拼写错误或无意错误。还有一些其他地方使用此 C++ 功能,例如:
struct iovec iov = { buf, sizeof(buf) };
struct sockaddr_nl sa;
struct msghdr msg;
struct nlmsghdr *nh;
msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
len = recvmsg(fd, &msg, 0);
for (nh = (struct nlmsghdr *) buf; NLMSG_OK (nh, len);
nh = NLMSG_NEXT (nh, len)) {
...
看来是有意识地选择了 C++。
Why does Linux man page provides C++ examples but not C?
Linux 手册页提供了 C 示例。他们不提供 C++ 示例。
I tried it in C, but it gives the error:
这是文档中的一个错误。应该是:
struct msghdr msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
我相信你可以 post 在 linux-man 邮件列表上提交错误报告。
Why there is no note about the language used in examples?
如所述on the project homepage, Linux man pages document the Linux kernel and the C library interface. The Linux kernel is written in C (primarily, there is some assembly, etc.)。因此,Linux 手册页以 C 编程语言提供示例。
What is this practice for and why is this not f.e. on Python or whatever?
惯例是在Linux的开发中使用C语言。它不是 Python 或任何其他语言,因为 Linux 内核是用 C 编程语言编写的。 Linux 内核是用 C 编程语言编写的,因为 Linux 内核的创建者 Linus Torvalds 很久以前就决定用 C 编程语言编写内核。
内核开发人员使用内核本身编写的语言为用户space程序分发内核接口API是最简单的,因此他们不必为用户重写它space 另一种编程语言的程序。它们还可以使用例如 user-space 在内核本身中使用的相同头文件。例如,这可以减少错误和工作量等。因此,内核开发人员最容易使用以 C 编程语言编写的示例来提供文档。