2

Can someone convert this C struct to delphi as in record?

typedef struct {
    Uint16    addr2:8;
    Uint16    addr1:8;
    Uint16    addr4:8;
    Uint16    addr3:8;
    Uint16    addr6:8;
    Uint16    addr5:8;
}MY_ADDR;

I tried it out myslef. But i couldn't figure out how to deal with addr2:8 (:8) issue.

MY_ADDR = record
  addr2:8 : Uint16;
  addr1:8 : Uint16;
  addr4:8 : Uint16;
  addr3:8 : Uint16;
  addr6:8 : Uint16;
  addr5:8 : Uint16;
  end;

I am not sure i also need this or not?

pMY_ADDR = ^MY_ADDR;
Sylvain Defresne
  • 42,429
  • 12
  • 75
  • 85
sMah
  • 455
  • 2
  • 8
  • 17
  • Just curious, what does the 8 signify? The width? Been a long time since I wrote C... – bnieland Mar 16 '11 at 00:25
  • 1
    They're bits. @SroMah, this may help: [bitfields] (http://stackoverflow.com/questions/282019/how-to-simulate-bit-fields-in-delphi-records) – Ken White Mar 16 '11 at 00:34

1 Answers1

4
MY_ADDR = record
  addr1 : Byte;
  addr2 : Byte;
  addr3 : Byte;
  addr4 : Byte;
  addr5 : Byte;
  addr6 : Byte;
end;

You need to swap them around due to byte ordering in MS C bitfields.

Erik
  • 88,732
  • 13
  • 198
  • 189