We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
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.
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.
Both those appearances are incorrect.