2

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.

Matt Joiner
  • 112,946
  • 110
  • 377
  • 526

2 Answers2

5

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.

Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
Alexander Rafferty
  • 6,134
  • 4
  • 33
  • 55
  • I don't know if apostrophe nitpicking is the done thing on SO, but you probably mean "pointers", as in the plural of pointer, not "pointer's", as in something belonging to the pointer. Have an upmod anyway. – Jack Kelly Sep 07 '10 at 03:39
  • This doens't seem right. I was always under the impression that fixed sized arrays are actually passed by value. A niggling point: This is C not C++. – Matt Joiner Sep 07 '10 at 03:41
  • 1
    If you wanted to pass by value, you could wrap it in a `struct`. – Jack Kelly Sep 07 '10 at 03:44
  • @Alexander Rafferty: Can you link to doc showing that fixed size arrays degrade to pointers when used as parameters? I'm guessing this doesn't apply to return values (where it really matters). – Matt Joiner Sep 07 '10 at 03:59
  • 1
    @Matt: See e.g. the [C FAQ](http://c-faq.com/aryptr/aryptrparam.html). You also can't return arrays by value either. – Georg Fritzsche Sep 07 '10 at 04:04
  • 1
    @Matt: Declaring a function with a return type that is an array type is illegal - and even if it weren't, you could never successfully pass an array to `return`, since it would always decay to a pointer to its first element. – caf Sep 07 '10 at 04:57
  • 2
    @Jack Kelly re apostrophe nit... since you ask, the SO approach to this kind of nit is (to borrow a phrase from a famous wiki) be bold and just go fix it, if you have enough rep to edit it. If not, patience will usually produce a user with enough rep who will fix it. That way, most of the broken windows get fixed without a lot of fuss about it. – RBerteig Sep 07 '10 at 06:57
  • I know it's pedantic but if anyone would like to link this answer, or link to in another answer the part of the C99 spec indicating that arrays degrade to pointers in return/parameters I'd be most appreciative. A cursory read of the C FAQ/N1256 did not turn up anything convincing. – Matt Joiner Sep 07 '10 at 08:53
  • 1
    The C99 reference you asked about is clause 6.7.5.3/1 (return type that is an array type is forbidden) and 6.7.5.3/7 (parameter of array type is changed to a pointer type) – Bart van Ingen Schenau Sep 07 '10 at 11:19
2

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.)

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
  • @Matt Joiner: at least `gcc` implements the syntactical part ;-) the real test for that is difficult to implement, I imagine. You'd either have to handle some sort of invariant (`is larger than`) on pointers or strictly restrict to array objects of the correct size. – Jens Gustedt Sep 08 '10 at 12:39