In article <[EMAIL PROTECTED]>, Jochen Immend�rfer wrote: > Hello, > > I've got a problem accessing global constant data. > > Situation: > > header.h: > extern const int global_int; > extern const int *pt; > > extern.c: > #include "header.h" > const int global_int = 23; > const int * pt = &global_int; > > main.c: > #include "header.h" > ... > if ( global_int == 23) > ... > if (*pt == 23) > ... > > > I'm using prc-tools 2.3 and pose. > > The first comparision running in pose gives me the message: > app just read from memory location 0x00002706, which is an unlocked chunk of > memory. > > The second comparision (the one with th pointer) works as expected. > > I've found similar problems on the list. I understood that the const data > is stored in the code-section, > and therefore only intra-segment references are allowed. > The solutions was either using the pointer-variant, or disabling the > "PC-relative const data"-switch in Codewarrior to force the const data > beeing stored > in data segment. > > I could not find a similar option for gcc. > Did I just not find it, or is there no posibility to get the code working? > main.c tries to reference global_int as an offset in the .data section, while it is assigned in the .code section in extern.c. The pointer pt is allocated in the .data section in extern.c and also referenced in the .data section in main.c. This is an other example of a long standing m68k-palmos-gcc bug. See the sourceforge project page (http://sourceforge.net/projects/prc-tools) go to Bugs and look up bug # 221845.
Workaround: remove the const atrribute from the global_int declarations. Ton van Overbeek -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
