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?


2 comments:

joy said...

As a person you should know what are your priorities and goals so that it is easier for you to determine and decide when is the time to give up or go on.
Thanks for sharing such a wonderful article, I hope you could inspire more people. Visit my site for an offer you wouldn't want to refuse.

jovie

www.n8fan.net

Leslie Lim said...


Thank you for posting some kind of information. It was really helpful since I am doing some research now.

Say
www.imarksweb.org