In article <[EMAIL PROTECTED]>, Daniel Seifert wrote: > Hi, > > the small test application I posted in source code below is giving me a > headache. What it basically should do is output "match found". But it > doesn't. The problem lies with the "TestStruct cmd[]". If I copy this > out of the function as a global, the app works fine. If it is inside the > function (local variable), the array is not accessible. Reducing the > array in size (e.g. removing one line or replacing "a" by a 0-pointer) > "solves" the problem, too. > > Compiling the application twice, once with MAX==10 (version "10") and > once with MAX==9 (and the last entry in the array removed) (version > "9"), I notice a difference: "10" has the following resources (+ prefs + > tAIN): > > 836 code0001.bin > 104 data0000.bin > 4 rloc0000.bin > > whereas "9" has these: > > 792 code0001.bin > 43 data0000.bin > > i.e. the rloc-resource is not used and the other resources are smaller. > If I use the "10" version but put the array outside the function, I get: > > 704 2003-11-20 22:03 code0001.bin > 104 2003-11-20 22:03 data0000.bin > 4 2003-11-20 22:03 rloc0000.bin > > The data and rloc resources are identical to the "10" version above, > only the code resource differs. > > Now, I basically know what the rloc resource is for (relocation), though > I'm unaware of the glory details. But still I believe that the code > below is correct and should produce "match found" as output, > unregardless of the size of the array or whether it is local or global. > > The obvious solution to my problem (using the array as global variable) > is not really a good one for me, as in the actual application I need to > have this array as a local variable. > > The compiler used is from prc-tools 2.3: > > Reading specs from /usr/lib/gcc-lib/m68k-palmos/2.95.3-kgpd/specs > Reading specs from /usr/lib/gcc-lib/m68k-palmos/specs > gcc version 2.95.3-kgpd 20010315 (release) > > Compilation was done by: > > pilrc -q test.rcp > m68k-palmos-gcc -Wall -c -o test.o test.c > m68k-palmos-gcc -Wall test.o -o test > build-prc test.def test *.bin > > > Looking forward to any reply that sheds some light on this issue. > > Daniel > If you compile your small test program with -S (=generate assembly) you see what is happening, For MAX=9 the cmd struct is initialized by code. For MAX=10 there is a copy in the .data section which gets copied to the stack at the start of the routine.
Here is where it goes wrong The memcopy which copies to the stack, takes its source address relative to the .text section. It should do it relative to the .data section. Hence your local copy on the stack contains garbage. I believe this is a long standing bug in prc-tools and I tried to find one of John Marshall's messages about it, but I could not find it. I hope John can comment on this. Workaround: Do not use initializers, initialize your struct via code. Ton van Overbeek -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
