tags:

views:

58

answers:

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.

+4  A: 

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.

Alexander Rafferty
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
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
no, any array is passed as a pointer to its first entry.
Alexander Rafferty
If you wanted to pass by value, you could wrap it in a `struct`.
Jack Kelly
@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
@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
@Matt: Could you accept this answer?
Alexander Rafferty
Easy, don't pressure prematurely: *"It is generally accepted that you should wait 24 to 48 hours to let a bunch of people have a chance to answer your question. A question with an accepted answer may deter people from looking at a question."* ... [FAQ](http://meta.stackoverflow.com/questions/5234/how-does-accepting-an-answer-work/5235#5235)
Georg Fritzsche
@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
@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
@RBerteig: Thanks. Now I know.
Jack Kelly
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
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
+1  A: 

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
Useful, I wonder if anyone uses or implements this.
Matt Joiner
@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