B
bitshadow
Hi all,
I'm implementing RFC3550 that requires me to create a header of n
number of bits. I've used a bit field to accomplish this. however i
realise i know little about bit fields and my C primer Plus doesn't go
into too much detail..
assuming i have the following structure:
typedef struct{
unsigned int v: 2;/*rtp version*/
unsigned int p: 1; /*rtp padding*/
unsigned int x: 1;/*extension bit*/
unsigned int cc: 4;/*csrc count*/
unsigned int m: 1;/*marker bit*/
unsigned int pt: 7;/*payload type*/
unsigned int sn: 16;/*sequence number*/
unsigned int ts: 32;/*time stamp*/
unsigned int ssrc: 32;/*synchronization source*/
unsigned int csrc: 32;/*contributing sources max 15*/
char *encoded_audio;
}rtp_hdr;
1)I understand that the bit field is just stored as an unsigned
integer and the total value of the bit field can't exceed the sizeof
unsigned int (32 bits) or 4 bytes is this correct?
2)assuming i have the above structure does that mean then that the
char variable - holding 40 bytes - would run into the first bit int v?
3)if i don't decalare a type and simply do:
typedef struct{
unsigned v: 2;/*rtp version*/
unsigned p: 1; /*rtp padding*/
unsigned x: 1;/*extension bit*/
unsigned cc: 4;/*csrc count*/
unsigned m: 1;/*marker b*
.......}
will the compiler automatically declare them as unsigned int?
4)in order to make sure the amount of bits i need fits into the
header struct does that mean i have to implicity declare short
integers to make them fit.
5)will my compiler store the bits in the way they are layed out or is
it compiler dependant.
thank you, i know its alot of questions (it's not homework) i just
want to make sure i understand how these work
so i can build this.
thank you very much,
Greg
I'm implementing RFC3550 that requires me to create a header of n
number of bits. I've used a bit field to accomplish this. however i
realise i know little about bit fields and my C primer Plus doesn't go
into too much detail..
assuming i have the following structure:
typedef struct{
unsigned int v: 2;/*rtp version*/
unsigned int p: 1; /*rtp padding*/
unsigned int x: 1;/*extension bit*/
unsigned int cc: 4;/*csrc count*/
unsigned int m: 1;/*marker bit*/
unsigned int pt: 7;/*payload type*/
unsigned int sn: 16;/*sequence number*/
unsigned int ts: 32;/*time stamp*/
unsigned int ssrc: 32;/*synchronization source*/
unsigned int csrc: 32;/*contributing sources max 15*/
char *encoded_audio;
}rtp_hdr;
1)I understand that the bit field is just stored as an unsigned
integer and the total value of the bit field can't exceed the sizeof
unsigned int (32 bits) or 4 bytes is this correct?
2)assuming i have the above structure does that mean then that the
char variable - holding 40 bytes - would run into the first bit int v?
3)if i don't decalare a type and simply do:
typedef struct{
unsigned v: 2;/*rtp version*/
unsigned p: 1; /*rtp padding*/
unsigned x: 1;/*extension bit*/
unsigned cc: 4;/*csrc count*/
unsigned m: 1;/*marker b*
.......}
will the compiler automatically declare them as unsigned int?
4)in order to make sure the amount of bits i need fits into the
header struct does that mean i have to implicity declare short
integers to make them fit.
5)will my compiler store the bits in the way they are layed out or is
it compiler dependant.
thank you, i know its alot of questions (it's not homework) i just
want to make sure i understand how these work
so i can build this.
thank you very much,
Greg