0

Given these byte range (an example I picked online), how to define this struct in C ?

These are byte ranges and not bit width. Also how in memory would this look like?

Bytes Description

07:00 The definition of this field is Fabrics response type specific.

09:08 SQ Head Pointer (SQHD)

11:10 Reserved

13:12 Command Identifier (CID)

15:14 Status (STS): Specifies status for the associated Fabrics command.

  Bits Definition ->Status (STS)
  15:01 Status Field
  00 Reserved
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
priti
  • 35
  • 1
  • 5

1 Answers1

0

You'll use arrays of char:

struct {
  char response_specific[8];
  char SQHD[2];
  char reserved[2]
  ...
}

You'll need to consider padding/packing issue (see here). This is important if you're expecting them to actually be stored in memory consequently (if, for example, you're trying to use it to parse a binary message from a file or a socket).

Alternatively you can just use one long char[] and use indexes to access the fields.

Weather Vane
  • 33,872
  • 7
  • 36
  • 56
littleadv
  • 20,100
  • 2
  • 36
  • 50