The code below generates this warning:
warning: cast to pointer from integer of different size
and I don't really understand why.
Can somebody please explain why?
The offending line is "Content = *((uint8_t*)Reg);
static uint8_t HandlePacket(TPacket *pMsg) { char *pCursor; uint8_t Content; uint8_t Reg;... switch( *pCursor) { case '>': pCursor++; switch( *pCursor) { case 'r': MsgOut.Data[0] = 'r'; pCursor++; Reg = GetUint32( &pCursor, 6 ); ItoaF( MsgOut.Data + 1, Reg, 4, 16); MsgOut.Data[5] = '='; // Reg is a number. // Cast it into a pointer to a register adress. // Take the contents of that register. // Cast the contents of that register to a uint8_t. Content = *((uint8_t*)Reg); ItoaF( MsgOut.Data + 6, Content, 4, 16); // Implicit uint8_t to uint32_t conversion. PacketSize = 10; break; } break;
A bit more background information:
Using: avr-gcc (GCC) 4.5.3
This code is meant for debugging.
My intent is to send an ascii string packed in a network packet (over uart/rs485). The avr decode's de commands and executes them en encodes the result again in another ascii string. Not the most efficient way of debugging, but most of the code already was in my project.
If I request the contents of 0x4c (TCNT1L) I get a different value each time, but the contents of the temporary register 0x4d (TCNT1H) only change after I've read TCNT1L. Other registers also seem to have plausible values.
Is this a search in the right direction?
paul@dualcore /usr/lib/avr/include/avr $ grep -nR "define _SFR_IO8" *.h
iom128rfa1.h:54:# define _SFR_IO8_STRUCT(io_addr,type) _MMIO_BYTE_STRUCT((io_addr) + 0x20, type)
sfr_defs.h:152:#define _SFR_IO8(io_addr) ((io_addr) + __SFR_OFFSET)
sfr_defs.h:179:#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET)