2010-09-07 25 views
2

这是代码行:这个夹板警告的含义是什么,我可能会做错什么?

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

运行夹板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) 

命名参数都没有区别。

回答

5

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

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

在C/C++,你不能要求一定规模作为参数数组,因为数组被视为一个指针,指针没有大小。

+0

我不知道,如果撇号挑剔是SO天经地义的事,但你可能是指“指针“,如在指针的复数中,而不是”指针的“,如在属于指针的东西中。反正有upmod。 – 2010-09-07 03:39:49

+0

这看起来不错。我总是觉得固定大小的数组实际上是按值传递的。一个小问题:这是C而不是C++。 – 2010-09-07 03:41:19

+1

不,任何数组都作为指向其第一个条目的指针传递。 – 2010-09-07 03:43:20

2

在C99(因为使用bool),必须添加static这样

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

签名(如果有在C这样的事情)是要求的参数阵列的最小长度的可能性思想,仍然是一个指针参数。

(还有我不知道任何现有的编译器做了明智的信息,但的。)

+0

有用的,我不知道是否有人使用或实现这一点。 – 2010-09-08 12:08:47

+0

@Matt乔伊纳:至少''gcc'实现了语法部分;-)真正的测试很难实现,我想。你要么必须处理指针上的某种不变量('大于'),要么严格限制到正确大小的数组对象。 – 2010-09-08 12:39:15