[NTLUG:Discuss] OT C question

Patrick R. Michaud pmichaud at pobox.com
Mon Feb 20 11:26:23 CST 2006


On Mon, Feb 20, 2006 at 09:57:09AM -0600, Johnny Cybermyth wrote:
> extern unsigned char *myarray;
> 
> void myfunc(unsigned char *somearray);
> 
> void main(void)
> {
> 	myfunc(&myarray);
> 	myarray[0] = '*';
> 	*(myarray+1) = '*';
> }
> 
> 1> The function call only worked when the & was added in front of 
> myarray.  

What do you mean by "worked" -- do you mean that it failed to compile
unless the & is in front of myarray, or that it compiled but didn't
run properly?  

If it didn't compile, what error message did you get?
If it compiled but wouldn't run, where are you actually creating
the "myarray" array?

> So, what I took away from this 
> little exercise is that if you declare an array using the char * method, 
> you have to use only that method when accessing the array, and the same 
> holds true for the [] method.  As for the function call, I don't 
> understand that at all.
> 
> Any thoughts?

Standard C and C++ have always held that

    array[n]
    *(array+n)

are equivalent, so it shouldn't have made any difference.  So
there must be something else going on here.

Pm





More information about the Discuss mailing list