Hi, I am a new user of Keil C compiler. During debug, I am trying to watch struct data members. But all of them show 0x0000. And they are not updated. With other variables it's just working fine. Any suggestions? Thanks, Titu
Maybe this is a bug in your code - are you sure that the structure members are actually being updated by your code? Have you tried stepping through a bit of code that ought to update (part of) the structure, and seeing what happens? "I am a new user of Keil C compiler." Did you start by reading the uVision Getting Started Guide, and working through the example projects in it? This would give you a proper introduction to the tools, how they work, and how to use them. (The uVision Getting Started Guide is available on the 'Books' tab in the 'Project' Window; The 'Books' window is also available via the 'Help' menu; failing all that, search for GS51.PDF in your Keil folder)
thank you for your kind response. I have skimmed through the GS51.PDF document. Still failed to find out a proper solution. The problems in detail: I declared and defined some structures in 3 header files and included them in other C files. structs are declared as static. The struct members are initialized by an initialization function. (I tried with defining the structs in header files and declaring them in one of the C files and then using 'extern' in other C files; but that does not work as well.) Now, I am trying to update those struct data from all the C files, in some cases using ISRs. The struct members are not updated while viewing in the watch window. As a solution, I tried with using only one header file and one C file those cover all the codes. This time, it updates the values for struct members. So, what was the problem with earlier version? Thanks a lot and happy new year.
"I have skimmed through the GS51.PDF document." I said you need to read the uVision Getting Started Guide, and work through the example projects in it - ie, study it thoroughly. You will not gain a proper understanding of anything by just skimming! You are probably still shooting in the dark.
"I declared and defined some structures in 3 header files" Well, that would be wrong for a start. I hope you mean that you defined each structure in exactly on 'C' file, and used 'extern' declarations in the headers? "structs are declared as static." The 'static' keyword limits the scope of an identifier to the file in which it is defined. Therefore, you probably have an independant instance of each structure in each of your 'C' files! ie, when one instance is updated in one file, none of the other instances is affected in any other file! You are probably watching one instance in one file while your code is updating another! I think you need to go back to your 'C' textbook.
"The 'static' keyword limits the scope of an identifier to the file in which it is defined." Hey, I think that's the reason! thanks a lot. Is it possible to use 'extern' for static structs in order to access them in other files? (Somewhere in this forum, I found that that does not work!) your suggestions and encouragements are certainly very much helpful. greetings, titu
Of course, that won't work. When declaring something static, you limit the scope of it to the file in which it is declared (if it's a file scope variable). What you want, is to have access to this item from external files, hence your proposal to make it external. To be able to do that, just don't use the word static when declaring the item in your c-file but instead declare it as external in the header file belonging to that c file. Use that header file in the other c-files where you want to have access to the item. -- Geert
"don't use the word static when declaring the item in your c-file but instead declare it as external in the header file belonging to that c file." Let's get the terminology correct here: "don't use the word static when defining the item in your c-file but declare it as external in the header file belonging to that c file." In other words: The definition needs to be in exactly one .c file - without the 'static' keyword; The 'extern' declaration should be in the header file. Remember: The definition is what actually creates the item - this is what causes memory to be allocated; The declaration merely provides information for other modules that need to access the item - it causes no memory allocation.
"Is it possible to use 'extern' for static structs in order to access them in other files?" No, it is not. I just explained what the 'static' keyword means, and so has Geert Vancompernolle; thus it should be obvious that 'extern' is meaningless with any 'static' item! See your 'C' textbook for further details.
Let's get the terminology correct here: "don't use the word static when defining the item in your c-file but declare it as external in the header file belonging to that c file." In other words: The definition needs to be in exactly one .c file - without the 'static' keyword; The 'extern' declaration should be in the header file. You've put it in an more correct context, Andy, which is absolutely OK. But you understood what I was trying to explain, and that's the most important for me! ;-) -- Geert
thanks Andy and Geert. I have got my codes into work following your suggestions :)