TIP: Click on subject to list as thread! ANSI
echo: cis.tandy.coco
to: Bob van der Poel 76510,2203 (X)
from: Mark Griffith 76070,41
date: 1990-05-03 06:20:29
subject: #3233-#C arrays

#: 3237 S10/Tandy CoCo
    03-May-90  06:20:29
Sb: #3233-#C arrays
Fm: Mark Griffith 76070,41
To: Bob van der Poel 76510,2203 (X)

Bob,

Let's flog the horse once more:

Your initial code had the array delcaration in the function as:

    int foo[20][6];

which will not work.  The compiler does just what you told it to do, point to
an array of pointers, each pointer of size 2 and 20, so you got 40 memory
locations between each element in the array.

    int foo[2][6];

will work since you are now telling the compiler the actual size of the column
element in the array, i.e. 2 bytes (the same as an int pointer).

    int foo[][6];

SHOULD work, I didn't try it.  Come to think some more, it probably doesn't
work since out compiler is not real smart when it comes to things like this. We
need to tell it what the array looks like.

The very best method is:

    int (*foo)[6];

since this is portable across any machine, even those with different size
int's.

Mark

There are 2 Replies.

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