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.
At the risk of receiving a good thrashing, I need to ask a basic C code beginner's question: I want to declare/define an array of struct in a .h file that assigns it to xdata memory. /* Struct.h */ xdata struct mode { int x,y,z; }; struct mode xdata type[5]; main.c () { struct_init(); modify_struct(); } struct_init () { type[0].x = 1; type[0].x = 2; type[0].x = 3; etc... } modify_struct() { type[0].x = newvalue; etc... } I'm confused as to how to make the struct visible to multiple files without getting: "Multiple Public Definitions" or "Unresolved External Symbol" etc... Any guidance from the experienced would be appreciated. Thanks
In a global.h file I only DECLARED the array of struct Wrong. You did not just declare the array of structs --- you defined it, because there's no extern keyword in your supposed declaration. Technically, that makes this a "tentative definition", but effectively, this turns into a definition of the array in every module you #include "struct.h" in. You should almost certainly drop the "xdata" qualifier from the definition of the struct type itself.