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.
Can anyone tell me why the following code for the C167 will place the pointer in either the NDATA0 class or the XDATA0 class depending on which line is uncommented? typedef struct { short type; } DIR_ENTRY; typedef DIR_ENTRY xhuge * DIR_PTR; //DIR_PTR test1; // Pointer placed in the XDATA0 class. DIR_ENTRY xhuge * test1; // Pointer placed in the NDATA0 class. I am using version 4.06 of the compiler. Thanks.
DIR_ENTRY xhuge *DIR_PTR;
typedef DIR_ENTRY xhuge * xhuge DIR_PTR;
I totally agree with you but that is not the situation I defined. My example was: DIR_PTR test1; not DIR_PTR xhuge test1; I have done some more work on this and found the following simpler example exhibits the same behavior: #define DIR_PTR_2 short xhuge * typedef short xhuge * DIR_PTR_1; // Using a typedef with a memory type (xhuge) in it incorrectly // places the pointer in the XDATA0 class. DIR_PTR_1 test1; // Using a #define will correctly place the pointer in NDATA0. DIR_PTR_2 test2; // This line correctly places the pointer in the NDATA0 class. short xhuge * test3; It seems that any time a memory type (xhuge, huge, etc.) is placed in a typedef, the variable is improperly stored.
Well since memory space qualifiers like code, xdata, data, idata, huge, etc. are not part of ISO C, unlike typedef's, then it's up to the implementer (Keil) to decide how to handle their own extension. I don't think this is a bug but simply how Keil decided to extend C. I for one never typedef pointers (nor do I include memory space qualifiers) so I've never had a problem with this. I would think a typedef should describe the type (it structure), not where it's to be stored. My two cents. - Mark
Mark, Thanks for the reply. I agree that it is not the best use of a typedef (I inherited this legacy code). However it is unfortunate that Keil chose to implement the feature in this fashion since the actual results are contrary to the expected behavior of a typedef. For this reason I would argue that it is still a defect. Barry
I agree that this is a defect--if not in implementation, at least in documentation. We should not have to waste time researching something that Keil should have documented adequately. "Quality is a product or service that meets or exceeds expectations." Clearly, your expectations are reasonable. (And this applies to the C51 toolset as well.) You have hit upon a worthwhile issue to explore re portability of compilers and associated tools. Do you know of a reference that has extensive examples of data declarations? Such a set of examples could be useful when becoming familiar with a new toolset.
Do you know of a reference that has extensive examples of data declarations? The C51 Compiler User's Guide really does have a lot of examples of data declarations as well as complex pointer declarations in Chapter 3. One of the biggest problems new users face is the challenge of learning C on an embedded architecture. One of the toughest problems to explain is illustrated by the following struct definition:
struct my_struct { int code var1; int data var2; int xdata var3; }; struct my_struct status;
Jon, While the C51 Manual may provide the info you stated, this was a C166 post. Is the current C166 manual on this site? The C166 manual I have is better than many I have had to work with, and yes, does provide many good examples as well. The example you showed is illuminating but it also is C51 specific. One of the biggest problems all users have is dealing with the individual quirks of each of the many tools that we work with on a daily basis. The best we can hope for is good timely support from the vendor and forums like this where others share their solutions to the problems we face. Thanks for the help. Barry
Oops, Well, I'm just friggin losing my mind. I shoulda noticed that this was a C166 questions. Normally, I'm perfect and make no mistakes! :-p The manuals for the C166 tools can be downloaded from the Evaluation Software page at: http://www.keil.com/demo/eval/c166.htm The file named DOC166... is the documentation file. It's kinda big (3M or so). Jon :-)
Apparently even the great ones slip occasionally. :-{))