Andrew Haley wrote:
Dimitry Golubovsky writes:
>
> If one wants to automatically determine offset of a regular field in a
> C structure, one uses `offsetof'
>
> According to the documentation,
>
> ==============
> This macro (offsetof) won't work if member is a bit field; you get an
> error from the C compiler in that case.
> ==============
Yes, because it's not addressable.
I ask this question in this thread because i think it is very much
similar ..
Suppose i have a struct like this ?
struct stream {
uint8_t stream_type: 8;
uint16_t reserved_1: 3;
uint16_t elementary_pid: 13;
uint16_t reserved_2: 4;
uint16_t es_info_length: 12;
void *descriptor;
};
struct pmt {
uint8_t table_id: 8;
uint16_t section_syntax : 1;
uint16_t reserved_1: 1;
uint16_t reserved_2: 2;
uint16_t section_length: 12;
uint16_t program_number: 16;
uint8_t reserved_3: 2;
uint8_t version_number: 5;
uint8_t current_next: 1;
uint8_t section_number: 8;
uint8_t last_section: 8;
uint16_t reserved_4: 3;
uint16_t pcr_pid: 13;
uint16_t reserved_5: 4;
uint16_t program_info_length: 12;
void *descriptor;
struct stream *streams;
};
The incoming bitsream is bigendian. My target platform is a desktop PC ,
little endian.
I was looking at how i can implement a parser based upon this structure,
without having to do a
* get_bits() using shifts and a mask
* or a shift and a mask alone.
I initially had the idea of copying the bitstream straight away to the
struct considering memory allocated is the same, trying to handle
endianness in some manner in the copy procedure.
If somebody could comment on what would be the best way to about it,
that would be quite helpful.
Thanks,
Manu