[comp.lang.c] Silly question...

bbs00068@uafcseg.uucp (Joel Kolstad) (07/06/90)

OK, You C Gurus out there... tell me something...  I want to go off and
allocate 2K of memory where I can store a bunch on numbers from 0-255.
This is on a PC, and the unsigned chars on my C compiler are 8 bits...
So, I thought I'd do this:

typedef unsigned char MyBytes;
MyBytes Mem[];
Mem=(MyBytes *) calloc(MemSize,1); /* MemSize=2048 */

But my compiler doesn't like this!  Instead, I have to replace the second line
with:

MyBytes *Mem; 

This is certainly equivalent, and the compiler eats it, but why doesn't the
first method work!?!?  Thanks!

Please mail replies to kolstad@cae.wisc.edu, since I don't log onto this
BBS to often (cae.wisc.edu is unable to post news right now!)

				---Joel Kolstad

throopw@sheol.UUCP (Wayne Throop) (07/11/90)

From: bbs00068@uafcseg.uucp (Joel Kolstad)
> MyBytes Mem[];
> MyBytes *Mem; 
> This is certainly equivalent,

It is certinly *NOT* equivalent.

This particular Frequently Promulgated Misconception (which is
addressed in lengthy detail on the Frequently Asked Questions list)
arouses my curriosity.

I would appreciate it if Joel (and anybody else who is now, or
who has ever been a holder of this heresy) would email me a short
summary of how they arrived at this error.  I'd like to gather a
sampling and see if there is a common reason for making this error.


BTW: in case it isn't clear: an array is NEVER a pointer.  In one
(ill considered, in my opinion) irregular place in the language
an array declaration is interpreted as a pointer declaration.
--
Wayne Throop <backbone>!mcnc!rti!sheol!throopw or sheol!throopw@rti.rti.org