这个夹板警告的含义是什么?我可能做错了什么?

发布于 2024-09-18 11:34:15 字数 521 浏览 13 评论 0原文

这是代码行:

bool cpfs_utimens(struct Cpfs *, char const *path, struct timespec const[2]);

运行 splint 3.1.2 会生成此警告:

cpfs.h:21:74: Function parameter times declared as manifest array (size
                 constant is meaningless)
  A formal parameter is declared as an array with size.  The size of the array
  is ignored in this context, since the array formal parameter is treated as a
  pointer. (Use -fixedformalarray to inhibit warning)

命名参数没有任何区别。

This is the line of code:

bool cpfs_utimens(struct Cpfs *, char const *path, struct timespec const[2]);

Running splint 3.1.2 generates this warning:

cpfs.h:21:74: Function parameter times declared as manifest array (size
                 constant is meaningless)
  A formal parameter is declared as an array with size.  The size of the array
  is ignored in this context, since the array formal parameter is treated as a
  pointer. (Use -fixedformalarray to inhibit warning)

Naming the parameter makes no difference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏末染殇 2024-09-25 11:34:16

这意味着当您声明参数 struct timespec const[2] 时,[] 之间的 2不是必需的。将代码更改为:

bool cpfs_utimens(struct Cpfs *, char const *path, struct timespec const[]);

在 C/C++ 中,您不能要求特定大小的数组作为参数,因为数组被视为指针,而指针没有大小。

It means that when you declare the parameter struct timespec const[2], the 2 between the [ and ] is not required. Changing your code to:

bool cpfs_utimens(struct Cpfs *, char const *path, struct timespec const[]);

In C/C++, you cannot ask for an array of a certain size as a parameter, because the array is treated like a pointer and pointers don't have sizes.

许久 2024-09-25 11:34:16

在 C99 中(因为您使用 bool),您可以通过像这样添加 static

bool cpfs_utimens(struct Cpfs *, char const *path, struct timespec const[static 2]);

签名来要求参数数组的最小长度(如果在C) 仍然是指针参数,我想。

(而且我还不知道任何现有的编译器可以根据这些信息做一些有意义的事情。)

In C99 (since you use bool) you have the possibility to require a minimum length of a parameter array by adding static like this

bool cpfs_utimens(struct Cpfs *, char const *path, struct timespec const[static 2]);

the signature (if there is such a thing in C) is still that of a pointer parameter, thought.

(And also I don't know of any existing compiler that does something sensible from that information, yet.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文