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_tstream_type: 8;
uint16_treserved_1: 3;
uint16_telementary_pid: 13;
uint16_treserved_2: 4;
uint16_tes_info_length: 12;
void*descriptor;
};
struct pmt {
uint8_ttable_id: 8;
uint16_tsection_syntax : 1;
uint16_treserved_1: 1;
uint16_treserved_2: 2;
uint16_tsection_length: 12;
uint16_tprogram_number: 16;
uint8_treserved_3: 2;
uint8_tversion_number: 5;
uint8_tcurrent_next: 1;
uint8_tsection_number: 8;
uint8_tlast_section: 8;
uint16_treserved_4: 3;
uint16_tpcr_pid: 13;
uint16_treserved_5: 4;
uint16_tprogram_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