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
Is this a feature introduced in C99?
I know keil c166 compiler only supports C90 but not C99. But i don't have those standards (no time to study and no money to buy), although i'd really like to spend some time to understand the C standrads.
From the draft of C99 from this link: www.open-std.org/.../n1256.pdf It mentioned the use of pointer to a table, like in page 122:
3 EXAMPLE: (d) int (*)[3] (d) pointer to an array of three ints
I cannot find C90 texts anywhere. But the Keil compiler does support this feature. So i guess it is already included in C90.
Normally i prefer to use a pointer to a table when there is a need to pass a table as a function parameter. This reminds me and other people to be careful to use correct memory objects when calling sth like:
extern void func(int (*conversion_table)[10]); int table_to_send[10]; func(&table_to_send);
In fact the Keil compiler doesn't check the table size, it passes the compiling if doing:
extern void func(int (*conversion_table)[10]); int table_to_send[9]; func(&table_to_send);
So the way I am doing is more like just a note for myself to send right table when calling a function.
About the huge (and far/xhuge) keyword, I just checked with assembly codes that it works in this way to define a pointer to a huge table:
int (huge *ptable)[10];