Compiler bug or misunderstanding? -- struct pointers

Hi,

DC 9.52 on RCM3700.

This looks like a compiler bug, but if I’m being dumb, just say :slight_smile:

Data:


//============================================
// New LED data structure.
//============================================

typedef struct
{
    short	CurrentCurve[101];		// (including board factors)
    char	Curve;
    // void	(*LED_on)(void);
    // void	(*LED_off)(void);
    // void	(*LED_level)(int);
    void	(*LED_on)();			// WARNING: Dynamic C does not allow parameter declarations
    void	(*LED_off)();			// here, so it can do no type checking or auto-promotion!
    void	(*LED_level)();			// (See user manual 4.16)
} t_Led_Data;

//============================================
// New Channel data structure.
//============================================

typedef struct
{
    char	Focus;
    char	State;				// (On/Off .. how to interwork with TTL?)
    char	Code;
    char	Bonded;
    char	Current_Max;			// in 1/10 Amp steps
    char	RQ_level;
    char	LED_level;
    char	POD_level;
    char	PCapp_level;
    char	chan_text[3];
    char	label[10];
    char	Switches;
    char	PhysicalControl;
    short	Temperature;			// in 1/10 degree steps.
    char	DigiPot[101];			//	 (tuneable?)
    // char	Peltier[101];			// <<= 2 (tuneable?)	Probably pointless.
    t_Led_Data	*pled_A;
    t_Led_Data	*pled_B;
    t_Led_Data	*pled_C;
    t_Led_Data	*pled_D;
} t_Channel_Data;

/* #memmap root .. didn't help */

t_Led_Data	Led_A;
t_Led_Data	Led_B;
t_Led_Data	Led_C;
t_Led_Data	Led_D;
t_Channel_Data	Channel_A;
t_Channel_Data	Channel_B;
t_Channel_Data	Channel_C;
t_Channel_Data	Channel_D;
t_Channel_Data	*pchan_A;
t_Channel_Data	*pchan_B;
t_Channel_Data	*pchan_C;
t_Channel_Data	*pchan_D;
t_Channel_Data	*Channel_Focus;		// points to channel that has the control focus

/* #memmap xmem .. didn't help */

The data is now part initialised, e.g. (from Watches):


-- pchan_B                 struct  *  0xBD33
+- *pchan_B               struct
     --...
     --...
     --...
     --...
     --...
     --RQ_level                char              0                 (offset 5)
     --LED_level               char              17               (offset 6)

But the following code does not see them as different:


    } else if( pchan_B->LED_level != pchan_B->RQ_level )
    {
          // Never gets here
    }

Single-stepping through the assembler is appears to do sensible things, reading in and calculating the address as I expect, but when it loads from the pointer-to locations, the data in the registers are both 0x0000 and, of course, the results are then equal so the test fails.

As you can see I tried putting the structs and pointers into root, but to no effect.

The calculated pointers are 0xBD38 and 0xBD39 as one would presumably expect.

Am I being dumb?

Thanks,
Gordon.

Hmmm,

Actually it does get there.

It looks rather as though the Watches data was not reflecting real data. The second time it hits that code, after another value is written into RQ_level, it works OK.

Strange.