home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!caen!kuhub.cc.ukans.edu!2hujwant
- From: 2hujwant@kuhub.cc.ukans.edu
- Newsgroups: comp.lang.c
- Subject: 2-D Arrays
- Message-ID: <1992Nov23.010230.45040@kuhub.cc.ukans.edu>
- Date: 23 Nov 92 01:02:29 CST
- Organization: University of Kansas Academic Computing Services
- Lines: 60
-
-
- OK. I have a question:
-
- How are two-dimensional arrays SUPPOSED to be defined?
-
- When I took my "intro to C" class, our teacher told us that you
- define them just like any other array, but with another index.
- i.e.:
-
- char some_array_name [dim1] [dim2]
-
- and that would take care of allocating the memory. BUT, he said, if
- we want to pass these arrays to a function, that the compiler, in
- its non-range-checking way would not know how the array was defined
- from just the pointer to a base address, (and I suppose this makes
- sense to me). So, he said, if we want a two-dimensional array that
- we can pass around to/from functions (and what good is an array that
- you couldn't?) we should define it thusly:
-
- typedef struct {
- char text[dim1][dim2];
- } 2-d_arraytype;
-
- 2-d_arraytype TheArray;
-
- And from there access it as:
-
- TheArray.text[row][col]
-
- Or pass it to a function as:
-
- void some_func (2-d_arraytype *a_pointer)
-
- And, of course, from there access it as:
-
- *a_pointer->text[row][col] = some_character;
-
- etc, etc, etc.
-
- My real question is, then, Is this the "correct" way to manipulate
- 2-d arrays, or is there a better way. The problem (for me) comes
- when I try to pass that array pointer to an external assembly
- routine. I don't think I understand exactly how that looks in
- memory, which is what you really need to know to do any real
- processing on it in assembly.
-
- So, if any of you veteran coders out there want to take the time to
- e-mail me a response to this, I would be very grateful. Also, if
- you do, I have plenty of other small/petty/novice-type questions
- that I could post, as long as no one gets too annoyed.
-
- Later!
-
- ====================================================================
- Sean White
-
- an Outlaw at
- The University of Kansas -- NCAA champs 1988 and 1993!
-
- ===================== 2hujwant@kuhub.cc.ukans.edu ==================
-