TIP: Click on subject to list as thread! ANSI
echo: cis.os9.68000.osk
to: Bob van der Poel 76510,2203 (X)
from: Bruce MacKenzie 71725,376
date: 1992-07-03 03:25:00
subject: #15751-Pointer help

 #: 15758 S12/OS9/68000 (OSK)
    03-Jul-92  03:25:00
Sb: #15751-Pointer help
Fm: Bruce MacKenzie 71725,376
To: Bob van der Poel 76510,2203 (X)

Bob,
     Yes, the way you've done the declaration is precisely the way it should be
done.  The declaration becomes clearer when one thinks of a 2D array as 1D
arrays nested inside a 1D array.  "int (*index)[DIM2]" declares index to be a
pointer to an array of integer arrays of size DIM2 in the same way that "int
*index" would declare index to be a pointer to an array of integers. In either
declaration the number of objects pointed to is irrelevant to the declaration,
only the size of the individual objects pointed to matters (the size of an
array of DIM2 integers in the first case or the size of a single integer in the
second case).  In a program one may want to assign the pointer to arrays of
various lengths and indeed one can:

 int (*index)[20],yes[5][20],no[10][20];
 .
 .
 .
 if(getchar()=='y')
      index=yes;
 else
      index=no;

index[2][3] would evaluate to the appropriate element in either array. (Of
course index[6][1] would be out of bounds if index were pointing to the yes
array) You needn't worry about changing what you #define DIM1 and DIM2 to be.
As long as you've used the macros consistently in your program changing their
values should not cause any problems.

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™.