Hi Guys,
I'm writing my own TCP/IP Stack. I've got following structure:
typedef struct __attribute__ ((packed)) { uint16_t type : 16; uint16_t protocol : 16; unsigned char hw_size : 8; unsigned char prot_size : 8; uint16_t op : 16; uint64_t srcMac : 48; uint32_t srcIP : 32; uint64_t dstMac : 48; uint32_t dstIP : 32; } ARP_Header;
If i want to compare the protocol value, the comparison isn't true, altough there is the right value in it.
if(rx_arp_header->protocol != ARP_PROT_Type_IP) { DEBUG("Protocoll Error: %x\n", rx_arp_header->protocol); return; }
ARP_PROT_Type_IP is defined by: #define ARP_PROT_Type_IP SWAP16(0x0800)
And SWAP16:
#define SWAP16(x) ((x & 0x00FF) << 8) | \ ((x & 0xFF00) >> 8)
I have found a workaround: I have to cast the SWAP16 value to an integer. Why? The code size is increasing about 200 Bytes.
Can you help me?
br Robert
> If i want to compare the protocol value, the > comparison isn't true, altough there is the right > value in it.
Did you mean to say is always true? That is what I get.
> I have found a workaround: I have to cast the SWAP16 > value to an integer. Why?
Perhaps it fixed the parentheses issue? You can't have enough parentheses in macros.
> The code size is increasing about 200 Bytes.
Because the compiler actually generated code for evaluating the condition in all cases where this macro has been used.
Regards Marcus http://www.doulos.com/arm/