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


---- test.c ----------------------------------- >o --------



struct {
        UInt16 number;
        char*  dummy;
} typedef TestStruct;

static void checkNumber(UInt16 x) {
        UInt16 i;

#define MAX 10
        TestStruct cmd[MAX] = {
                {  1,  "a" },
                {  2,  0 },
                {  3,  0 },
                {  4,  0 },
                {  5,  0 },
                {  6,  0 },
                {  7,  0 },
                {  8,  0 },
                {  9,  0 },
                { 10,  0 }
        };

        for (i = 0; i<MAX; i++) {
                if (x == cmd[i].number) {
                        SysFatalAlert("match found\n");
                }
        }
}

UInt32 PilotMain(UInt16 cmd, void *cmdPBP, UInt16 launchFlags) {
        UInt32 t;

        switch (cmd) {
                case sysAppLaunchCmdNormalLaunch:
                        checkNumber(1);
                        t = TimGetSeconds(); while(TimGetSeconds() < t+5);
                        
                        break;

                default:
                        break;
        }

        return 0;
}
-- 


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to