MCU: 51 compatible mcu from ATMEL
When we used the generic pointer to as the function's
parameter, the address is not correct, and the pointer
fly to anywher. Can anyone tell how this happen?

Example source here:
#define BITS_PER_CHAR                  8
#define BITS_TO_CHARS(bits)            \
        (((uint8_t)((bits)+BITS_PER_CHAR-1))/((uint8_t)BITS_PER_CHAR))

#define DECLARE_BITMAP(name, bits)     \
        volatile uint8_t name[BITS_TO_CHARS(bits)]

uint8_t bitmap_hweight(const volatile uint8_t *addr, uint8_t size)
{
        uint8_t nr = 0, i;
        for (i = 0; i < BITS_TO_CHARS(size); i++)
                nr += hweight8(addr[i]);
        return nr;
}

uint8_t hweight8(uint8_t byte)
{
        uint8_t res = byte - ((byte >> 1) & 0x55);
        res = (res & 0x33) + ((res >> 2) & 0x33);
        return (res + (res >> 4)) & 0x0F;
}

#define SAMPLE_BITS        0x0E
pdata DECLARE_BITMAP(bmp_sample, SAMPLE_BITS);

/* here comes the problem:
   the local variable "addr[0]" and "addr[1]" in the function
        bitmap_hweight(bmp_sample, SAMPLE_BITS);
   is not equal to "bmp_sample[0]" and "bmp_sample[1]"
 */

Thanks.
------------------------------------------------------------------------------
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to