#: 3417 S10/Tandy CoCo
11-May-90 11:39:36
Sb: #3414-C arrays
Fm: Jeff Dege 76426,211
To: Bob van der Poel 76510,2203
There is a very interesting article in the May 1990 issue of "The C Users
Journal" on exactly this subject (it's the issue with "The REAL Obfuscated Code
Contest" ;) Page 25, "Dr. C's Pointers - Pointers To Arrays", by Rex Jaeschke.
And NO, I didn't see the article until after my post. Like most things in C,
it wasn't until I got bitten hard that I figured this stuff out. I was writing
some matrix routines for a graphics class, and it took me quite a while to
figure out why things weren't happening the way I had thought they would.
The most common reason for mixing pointer and array notation is so that you
can use dynamically allocated arrays. Something like this:
int (*foo)[10];
foo = (*)[10] malloc(20*sizeof(*foo)); /* foo is now a 20x10 array */
If you are looking for another "innocent" question, start asking about
mixing signed and unsigned chars and ints in expressions. Things can get VERY
hairy there. I've never really dug into the area (I never mix signed and
unsigned, and I never use lone chars), so I can't explain all the details on
it, but you can be sure to generate an argument...
|