Mostly Bollogs, I'm afraid

But occasionally, a glimmer of truth.
If you find one, please let me know.



Thursday 20 November 2014

Straight C

I have something that works.

It is GCC and on a 16bit machine, so int is 16 bits.

typedef unsigned int uint16;

#define NO_OF_BATTERIES 2
#define TIME_AVERAGE 5
uint16 aa_timeAverage[NO_OF_BATTERIES][TIME_AVERAGE]={1,2,3,4,5,6,7,8,9,0xa};

uint16* pNewTimeValue;

void main(void) {
    int iBattery=0;
    pNewTimeValue = aa_timeAverage[iBattery]);             // store pointer for new time average value
    memmove(aa_timeAverage[iBattery]+1,                       // destination: element 1
         aa_timeAverage[iBattery],                                         // source: element 0
        sizeof(uint16)*(TIME_AVERAGE-1));                     // shift up Time Values
    *pNewTimeValue=99;
}

If I change it to:

    memmove(aa_timeAverage[iBattery]+1,                      // destination: element 1
        &(aa_timeAverage[iBattery][0]),               // source: element 0
        sizeof(uint16)*(TIME_AVERAGE-1));                          // shift up Time Values

I need to cast as (const uint16 *)&(aa_timeAverage[iBattery[0]) to stop a compiler "suspicious pointer" warning.

Anyone know why?


No comments: