This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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
  • Then, with all due respect, I suggest you take the time to revisit your C textbooks' chapters' on pointers.

    Thank you, I just did. Apparently, I wasn't paying enough attention when reading it the first time. Pointers to arrays are discussed briefly in K&R in connection with multidimensional arrays and function arguments. I guess it's my turn to eat the humble pie.
    In relation to the original poster's intention, it appears that pointers to arrays are not designed to facilitate out-of-bounds checking. Moreover, it appears that they can only be useful when working with multidimensional arrays.

Reply
  • Then, with all due respect, I suggest you take the time to revisit your C textbooks' chapters' on pointers.

    Thank you, I just did. Apparently, I wasn't paying enough attention when reading it the first time. Pointers to arrays are discussed briefly in K&R in connection with multidimensional arrays and function arguments. I guess it's my turn to eat the humble pie.
    In relation to the original poster's intention, it appears that pointers to arrays are not designed to facilitate out-of-bounds checking. Moreover, it appears that they can only be useful when working with multidimensional arrays.

Children