Orphaned Response

karl at haddock karl at haddock
Sat Sep 6 01:09:00 AEST 1986


killer!tad (Tad Marko) writes:
>In my original article, ... I was asking if I should use
>"foo(parm) char **parm; {...}" or "foo(parm) char *parm[]; {...}"
>and I *DID* test both of them, and they both worked.

Okay, that's a more sensible question.  The official truth is that in this
context, they are equivalent.  However, my *personal opinion* is that the
former is "more correct"; the latter is a kludge where the compiler figures
out what you "must have really meant" and converts it for you.  (Kind of like
how some compilers will interpret "&a" as "&a[0]" if "a" is an array, though
in that case you'll probably get a warning at least.)

My recommendation is to write "char **parm"; it causes less confusion.  Even
if you do write "char *parm[]", you are declaring a pointer, not an array.
(Similarly, a formal argument declared "float parm" really declares a double,
which is also quite confusing, e.g. if you take its address.)

Oh yes, some compilers used to consider a parameter declared "type x[]" to be
a *non-modifiable* pointer to type.  That no longer seems to be popular.

Karl W. Z. Heuer (ima!haddock!karl; karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list