address of structure element

I am using WinARM gcc and Programmers Notepad for an ethernet project.

Using the following structures, if I try to access ARP_BUF->ethhdr.type I should get the contents of 7fe180c. I get the contents of 7fe01810.

struct uip_eth_addr {

uint8_t addr[6];

};

struct uip_eth_hdr

{

struct uip_eth_addr dest;

struct uip_eth_addr src;

uint16_t type;

};

struct ethip_hdr {

struct uip_eth_hdr ethhdr;

/* IP header. */

uint8_t vhl,

tos,

len[2],

ipid[2],

ipoffset[2],

ttl,

proto;

uint16_t ipchksum;

uint16_t srcipaddr[2],

destipaddr[2];

};

ARP_BUF= (struct ethip_hdr *)EMAC_RX_BUFFER_ADDR;

EMAC_RX_BUFFER_ADDR = 7fe01800

It appears that only 32bit addresses are accessed. I have tried a variety of castings, but its always 32bit addresses.

lee_h

Typo in this posting we assume…7fe180c s.b. 7fe0180c (missing 0)

I should get the contents of 7fe180c. I get the contents of 7fe01810.

and EMAC_RX_BUFFER_ADDR = 7fe01800 of course would be prefixed 0x

I’ll guess that your compiler options are set to align structures on size_t boundaries.

I use IAR, not GCC, and it has a pragma to control this line by line, and a global default.

I’ve coded this same scheme for the long set of registers and buffers in the WizNet chip - but I used all uint8_t types in the arrays to avoid sizeof() issues in CPU portability and compilers.

I agree, gcc is probably padding the structure members so they’re aligned for more efficient access. You can use a gcc [attribute or [pragma to affect this, though I usually prefer to do the offset calculations myself and not rely on the compiler to generate a specific memory layout for a structure.](http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html)](Variable Attributes (Using the GNU Compiler Collection (GCC)))