Re: Offset and Bit Mask for Bit Fields?

2005-07-11 Thread Manu Abraham

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








typedefs

2005-11-21 Thread Manu Abraham

Hi,

When one does a

typedef uint8_t array[10];

what does really happen ?


For example, i was looking at some code in the public domain, which had 
it like this ..


u8 is again typedef'd from a unsigned char

#define TS_PACKET_SIZE 188
#define TS_IN_UDP 7

typedef u8 file_ts_packet[TS_PACKET_SIZE];
typedef file_ts_packet udp_packet[TS_IN_UDP];

struct s_own_pcr
{
int start, end;
pthread_mutex_t lock;
file_ts_packet *buf[(TS_BUFFER_SIZE+1)*TS_IN_UDP+1];
};


struct s_in_data
{
int start, end;
pthread_mutex_t lock;
pthread_cond_t notfull;
pthread_cond_t notempty;
int b_die;
udp_packet buf[TS_BUFFER_SIZE+1];
};



So i was wondering what buf would be now. it will be a 1 dimensional array ?
If it is a 1 dimensional array, what could this part of the code 
probably mean .. ?


/* If we have 2 consecutiv PCR, we can reevaluate slope */
if( (own_pcr.start != own_pcr.end) &&
no_discontinuity &&
!u8*) next_pcr = own_pcr.buf[own_pcr.start]))[5] & 0x80))
{



}

I was wondering what the last condition could probably mean ..


Thanks,
Manu