odd bit field problem 
Author Message
 odd bit field problem

Hi:

Can I use bit-fields with a type other than unsigned (implied int)?  I'd
like to use them with unsigned chars.  Long fat pipe at the amazing rate of
50 bps.  Parsimonious bit usage.

My TPOP inspired raw to host un/packing and marshalling routines run good
with a uchar.  Possibly a situation where hardware overrides ANSI
compliance?  The gods of design made sure a byte would be surrounded by 4
or 8 byte values.

so, how can I comply when 8 bits are sent between 4 ot 8 byte quantities?

Thanks,
        Dave

P.S.  I did search the FAQ on both bit and fields before posting :-)...



Wed, 10 Dec 2003 14:26:25 GMT  
 odd bit field problem
David Johns a crit dans le message ...
Quote:
>Can I use bit-fields with a type other than unsigned (implied int)?

I'd

Any unsigned type is fine (char, short, int, long, long long).

Quote:
>like to use them with unsigned chars.  Long fat pipe at the amazing

rate of

No problemo.

Quote:
>50 bps.  Parsimonious bit usage.

>My TPOP inspired raw to host un/packing and marshalling routines run

good

TPOP?

Quote:
>with a uchar.  Possibly a situation where hardware overrides ANSI

There is no uchar in C. I guess you mean unsigned char. Unsigned char
are well known for beeing the most portable object for interfaces.

Quote:
>compliance?  The gods of design made sure a byte would be surrounded
by 4
>or 8 byte values.

Do you mean bit or byte?

Quote:
>so, how can I comply when 8 bits are sent between 4 ot 8 byte

quantities?

It's unclear to me. Can you elaborate, give an example, post some
code?

--
-hs-    "spaces, not tabs" email: emdel at noos.fr
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkumware.com/htm_cl/index.html
FAQ de FCLC : http://www.isty-info.uvsq.fr/~rumeau/fclc



Wed, 10 Dec 2003 15:13:20 GMT  
 odd bit field problem

Quote:

> David Johns a crit dans le message ...
> >Can I use bit-fields with a type other than unsigned (implied int)?
> I'd

> Any unsigned type is fine (char, short, int, long, long long).

Nope.  Bit-fields must have a type "that is a qualified or
unqualified version of one of int, unsigned int, or signed int."
Whether a plain `int' bit-field is signed or unsigned is
implementation-defined.
--
"Some people *are* arrogant, and others read the FAQ."
--Chris Dollin


Wed, 10 Dec 2003 22:51:42 GMT  
 odd bit field problem
In the file with the structure definition, you could pack it down to use
minimal space.

#pragma pack(1)
#pragma pack() // or #pragma pack(4).

This should allow your structures to align on 1-byte boundaries instead of
4-byte boundaries.

(Above is for gcc - not sure about MS Visual C or others).  Of course, I
understand there's a performance tradeoff when structures aren't aligned on
4-byte boundaries, but I haven't noticed anything.

Philodux


Quote:

> Hi:

> Can I use bit-fields with a type other than unsigned (implied int)?  I'd
> like to use them with unsigned chars.  Long fat pipe at the amazing rate
of
> 50 bps.  Parsimonious bit usage.

> My TPOP inspired raw to host un/packing and marshalling routines run good
> with a uchar.  Possibly a situation where hardware overrides ANSI
> compliance?  The gods of design made sure a byte would be surrounded by 4
> or 8 byte values.

> so, how can I comply when 8 bits are sent between 4 ot 8 byte quantities?

> Thanks,
>         Dave

> P.S.  I did search the FAQ on both bit and fields before posting :-)...



Fri, 12 Dec 2003 07:44:32 GMT  
 odd bit field problem
[...]

Quote:
> Nope.  Bit-fields must have a type "that is a qualified or
> unqualified version of one of int, unsigned int, or signed int."
> Whether a plain `int' bit-field is signed or unsigned is
> implementation-defined.

In addition, C99 allows bit-fields of type _Boolean or "some other
implementation-defined type".

--

San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Cxiuj via bazo apartenas ni.



Fri, 12 Dec 2003 08:07:58 GMT  
 odd bit field problem

Quote:

> In the file with the structure definition, you could pack it down to use
> minimal space.

> #pragma pack(1)
> #pragma pack() // or #pragma pack(4).

"#pragma pack" is non-standard.

--

San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Cxiuj via bazo apartenas ni.



Fri, 12 Dec 2003 13:45:16 GMT  
 odd bit field problem

Quote:


> > David Johns a =E9crit dans le message ...
> > >Can I use bit-fields with a type other than unsigned (implied int)?
> > I'd
> >=20
> > Any unsigned type is fine (char, short, int, long, long long).

> Nope.  Bit-fields must have a type "that is a qualified or
> unqualified version of one of int, unsigned int, or signed int."

Add _Bool for C99 :)

Micah

--
Computers are basically very fast idiots.



Wed, 17 Dec 2003 09:04:34 GMT  
 odd bit field problem

Quote:
> Can I use bit-fields with a type other than unsigned (implied int)?  I'd
> like to use them with unsigned chars.

As others have answered, only signed and unsigned int
are guaranteed in C89.  But the whole point of bitfields
is that they can and should be packed even below
the smallest addressable unit (any character type).
Any compiler that doesn't pack within a byte
(= unsigned char by definition in C) a bitfield
that fits within that byte (unless you used : 0)
is abysmally low quality and should be replaced.
A bitfield larger than a byte can reasonably require
a storage unit (also) larger than a byte -- but
you presumably wouldn't expect to define
such a bitfield using uchar type anyway.

Note however that you can't depend on the order
of bitfields within a byte or other storage unit
(i.e. low bit first or high bit first) so they aren't
safe for an inter-system wire protocol.

If you want to pack byte or larger objects
to _byte_ boundaries, the (only) portable way
is to memcpy them together and back apart
(or memmove if you want to do it in place).
If you are un/marshalling anyway, as you
indicate, this might actually be free.

PS- "fat" means _high_ bandwidth.  50bps is
a (perhaps long) _narrow_ pipe.  You might
want to consider even more efficient but
complicated encodings like ASN.1 PER,
or real compression (comp.compression
for the latter, and maybe the former).

--
- David.Thompson 1 now at worldnet.att.net



Fri, 19 Dec 2003 12:42:21 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Help! 32 bit words using bit fields

2. 32-bit bit fields?

3. Bit-field problem with uneven bits

4. bit field problem

5. Structure bit field alignment problem

6. Problem with bit fields inside a struct declaration

7. problems with bit fields in structures

8. Problems with bit fields as booleans

9. Bit-field portablility problem

10. memcpy()-like move to odd bit

11. Porting 16-bit Win 3.11 dll to 32-bit NT (odd problem) Keywords: DLL DEF exports registry Ingres OpenRoad 4GL

12. Porting 16-bit Win 3.11 dll to 32-bit NT (odd problem) Keywords: DLL DEF exports registry Ingres OpenRoad 4GL

 

 
Powered by phpBB® Forum Software