About pointer to a huge table in C

Hi,

I am a bit confused about writing codes with a poitner pointed to a huge table in C with Keil compiler (for C166 MCU).

First if i want to define a pointer pointed to a huge table, naturally i would do:

int huge (*ptable)[256];

However the complier does not allow to write in this way. The only way to pass the compiling is:

int (huge *ptable)[256];

The codes seem to work like this. But i am not really sure if i defined the pointer in a correct way, Can someone confirm me about it?

Second question about type cast. If i want to convert something into a pointer, I found i can do both type casts:

long addr;
int (huge *ptable)[256];

ptable = (int huge (*)[256])(&addr);
ptable = (int (huge *)[256])(&addr);

Both of the 2 lines above seem to work. But i am confused why the complier allows to define a point only in 1 way but allows type cast in 2 different ways? Does anyone knows the story under the hood?

Thanks for the help.

Regards,
Xiang

Parents
  • ...naturally i would do...

    This seems natural to you, but it's nowhere near natural to me. You should declare pointers to arrays in the same way everyone does: as pointers to a single element of the array:

    int huge *ptable;
    


    The K&R book has a very good discussion about arrays and pointers. You should read it.

    Regards,

    - mike

Reply
  • ...naturally i would do...

    This seems natural to you, but it's nowhere near natural to me. You should declare pointers to arrays in the same way everyone does: as pointers to a single element of the array:

    int huge *ptable;
    


    The K&R book has a very good discussion about arrays and pointers. You should read it.

    Regards,

    - mike

Children
More questions in this forum