* Offset and Bit Mask for Bit Fields?
@ 2005-07-11 14:08 Dimitry Golubovsky
2005-07-11 14:13 ` Andrew Haley
0 siblings, 1 reply; 3+ messages in thread
From: Dimitry Golubovsky @ 2005-07-11 14:08 UTC (permalink / raw)
To: gcc
Hi,
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.
==============
Do there exist any means in gcc to measure offsets (of enclosing
integer field) and bit mask for bit fields?
If not, any chance to add them in the future?
--
Dimitry Golubovsky
Anywhere on the Web
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Offset and Bit Mask for Bit Fields?
2005-07-11 14:08 Offset and Bit Mask for Bit Fields? Dimitry Golubovsky
@ 2005-07-11 14:13 ` Andrew Haley
2005-07-11 14:53 ` Manu Abraham
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Haley @ 2005-07-11 14:13 UTC (permalink / raw)
To: Dimitry Golubovsky; +Cc: gcc
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.
> Do there exist any means in gcc to measure offsets (of enclosing
> integer field) and bit mask for bit fields?
No.
> If not, any chance to add them in the future?
I doubt it. We're very reluctant to add new language extensions to C,
and this one would be very problematic.
Andrew.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Offset and Bit Mask for Bit Fields?
2005-07-11 14:13 ` Andrew Haley
@ 2005-07-11 14:53 ` Manu Abraham
0 siblings, 0 replies; 3+ messages in thread
From: Manu Abraham @ 2005-07-11 14:53 UTC (permalink / raw)
To: gcc
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-07-11 14:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-11 14:08 Offset and Bit Mask for Bit Fields? Dimitry Golubovsky
2005-07-11 14:13 ` Andrew Haley
2005-07-11 14:53 ` Manu Abraham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).