Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!orchid!rbutterworth From: rbutterworth@orchid.UUCP Newsgroups: comp.lang.c Subject: More on passing arrays to functions. Message-ID: <9857@orchid.waterloo.edu> Date: Wed, 22-Jul-87 09:56:27 EDT Article-I.D.: orchid.9857 Posted: Wed Jul 22 09:56:27 1987 Date-Received: Sat, 25-Jul-87 01:31:11 EDT Distribution: comp Organization: U of Waterloo, Ontario Lines: 32 Has anyone noticed the definition (source and man page) for scandir(3) in BSD? int scandir(dirname, namelist, select, compar) char *dirname; struct direct *(*namelist[]); int (*select)(); int (*compar)(); What does "struct direct *(*namelist[]);" mean? Well, it's an array of pointers to pointers to structures. But what did the authors really want (the redundant parentheses sort of indicate that they thought they were doing something else)? You are supposed to supply the address of a pointer that will be stuffed with the address of the newly allocated array. So what they needed was a pointer to a pointer to an array of structures, i.e. "struct direct (**namelist)[];". But of course K&R C won't let you generate pointers to arrays in many circumstances, so what they really needed was a pointer to a pointer to the first member of an array of structures. i.e. "struct direct ***namelist;". Not the same thing at all. But C, being the friendly language that it is, silently turns the incorrect parameter type "**namelist[]" into the correct "***namelist". Wasn't that nice of it?