I would recommend against using the []
syntax for function parameters.
The one argument in favour of using []
is that it implies, in a self-documenting manner, that the pointer is expected to point to more than one thing. For example:
void swap(int *x, int *y)
double average(int vals[], int n)
These prototypes demonstrate the semantic difference. However, the ubiquitous C string, char *
, disagrees with this point (have you even seen char str[]
in a function parameter list? I haven't.)
Some people like to const
everything they possibly can, including pass-by-value parameters. The syntax for that when using []
(available only in C99 IIRC) is less intuitive and probably less well-known:
const char *const *const words
vs. const char *const words[const]
Although I do consider that final const
to be overkill, in any case.
Furthermore, the manner in which arrays decay is not completely intuitive. In particular, the fact that it is not applied recursively (char words[][]
doesn't work). Especially when you start throwing in more indirection, the []
syntax just causes confusion. IMO it is better to always use pointer syntax rather than "pretending" that an array is passed as an argument.
More information: http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=aryptr#aryptrparam.