TIP: Click on subject to list as thread! ANSI
echo: cis.tandy.coco
to: Mark Griffith 76070,41 (X)
from: Jeff Dege 76426,211
date: 1990-05-03 20:36:04
subject: #3237-C arrays

#: 3250 S10/Tandy CoCo
    03-May-90  20:36:04
Sb: #3237-C arrays
Fm: Jeff Dege 76426,211
To: Mark Griffith 76070,41 (X)

   Bull!

  From K&R 2, p. 112, (where his previous example used a [2][13] array):

   If a two-dimensional array is to be passed to a function, the parameters
declaration in the function must include the number of columns; the number of
rows is irrelevent, since what is passed is, as before, a pointer to an array
of rows, where each row is an array of 13 ints.  In this particular case, it is
a pointer to objects that are arrays of 13 ints.  Thus if the array daytab (his
example) is to be passed to a function f, the declaration of f would be

   f(int daytab[2][13]) { ... }

It could also be

   f(int daytab[][13]) { ... }

since the number of rows is irrelevent, or it could be

   f(int (*daytab)[13]) { ... }

which says that the parameter is a pointer to an array of 13 integers. The
parentheses are necessary since brackets [] have higher precedence than a *. 
Without parentheses, the declaration

   int *daytab[13]

is an array of 13 pointers to integers.  More generally, only the first
dimension (subscript) is free; all the others have to be specified.

(END OF QUOTE)

  As you see, the first dimension is not required, and is ignored if supplied,
but it is NOT incorrect, nor should it change the behavior of the function. 
When the compiler sees "int foo[20][6]" AS A PARAMETER, it should treat it as a
pointer to a 6 element array of ints.  If it doesn't, it is broken.

SOURCE: compuserve via textfiles.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.