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
"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 :)