[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need Orca/C help...
In article <> jlee@Bonnie.ICS.UCI.EDU ("Joseph T. Lee") writes:
>The difference comes from what kind
>of code you write to access them. Well using calloc it would be:
>
>int *array;
>array = (int *) calloc(100 * 100, sizeof(int));
>
>then you access it like any other array:
>
>array[5][10] = 1
>getvalue = array[5][10]
No no no... because it was allocated as a single piece of memory, it
has no idea whatsoever how big the "rows" are.
You may be able to declare a pointer-to-small-array, like
int (*array)[10];
but I can never get those right...
>BTW, you can do this with any pointer, it's just not efficient. That's where
>pointer math comes in, but (hint, hint :) it's something you should look at.
No, the compiler usually converts freely between p[i] and *(p+i)...
shouldn't make a difference.
>I don't suggest using calloc nor malloc calls unless you know what you're
>doing and you're writing really weird code. The simple initialization during
>the declaration of the array should be just fine.
Only if it's supported, and only the first time. If you have to
reinitialize, you're screwed.
--
Donald Tsang tsang@cs.washington.edu ...!uw-beaver!june!tsang
A radioactive cat has 18 half-lives -- [/usr/games/fortune]