China Blue Veins
3/18/2011 5:29:00 AM
In article <e0dc3b80-b72e-4ba1-aa11-b3c530b95924@18g2000prd.googlegroups.com>,
Cuthbert <cuthbert.kao@gmail.com> wrote:
> Hi guys,
>
> I am trying to use a single array to access multiple 2D arrays but
> I kept getting the error message. Could someone help me on this? Thank
> you very much.
Because you're lying to the compiler. access_ary is ((u16*)[]) and thus can only
take two subscripts, not three. I don't know of any straightforward way to
encode your intention. Unfortunately the C type system was designed to be clever
rather than orthogonal, so you can't express every possible concept in the
language.
>
> Here is my code:
> // Definition
> u16 const_1[4][2] ={
> {25,65},
> {23,65},
> {2,777},
> {2,13}
> };
>
> u16 const_2[4][2] ={
> {15,65},
> {13,65},
> {1,5},
> {1,13}
> };
>
> u16 *access_ary[2] = {
> const_1,
> const_2};
>
> ..............
> // access them
> k = access_ary[0][2][1]; // expecting k=777
int main(int n,char **p) {
printf("%d\n",access_ary[0][2*2+1]); /*do the subscript computation by hand*/
return 0;
}
/ cc t.c
t.c:18: warning: initialization from incompatible pointer type
t.c:19: warning: initialization from incompatible pointer type
/ a.out
777
--
Damn the living - It's a lovely life. I'm whoever you want me to be.
Silver silverware - Where is the love? At least I can stay in character.
Oval swimming pool - Where is the love? Annoying Usenet one post at a time.
Damn the living - It's a lovely life. Alameda County Sheriff.