![]() |
|
#1
|
|||
|
|||
need urgent helphow to pack eight different single bit field into one eight bit character byte?
single bit field is char single:1 |
|
#2
|
|||
|
|||
Re: need urgent helpgoogle: bit shift
|
|
#3
|
|||
|
|||
Re: need urgent helpi got one solution
CPP / C++ / C Code:
Last edited by admin II : 14-May-2008 at 17:18.
Reason: Please surround your C code with [cpp] your code [/cpp]
|
|
#4
|
|||
|
|||
Re: need urgent helpin above solution it will allocate data to all members of union. is there any way to allocate to only one member out of several
|
|
#5
|
|||
|
|||
Re: need urgent helpQuote:
A union is a single storage unit (block of memory). Its size is the size of its largest member. For a bit field, the compiler allocates a storage unit large enough to hold the total number of bits. (There is no guarantee what the actual size is; it is just guaranteed to be "large enough.") For a struct, the compiler allocates a storage unit large enough to hold all of its members. In all cases, the compiler may actually allocate enough storage to make successive declared items be aligned in such a way that the compiler deems desirable (typically for best access speed). Bottom line: The actual amount of storage that a compiler uses for a bit field or a union or a struct is implementation-dependent (that is, different compilers may allocate different amounts of storage). Here's something to try: Declare all of the members of the flagtype struct to be unsigned char. This is actually not specifically allowed by the C language standard, but it works for all of the compilers that I use these days. See footnote. If this works and you are satisfied, then we are done. If you want a guaranteed portable method to make sure everything gets packed into a single char, then I think you are SOL (Somewhat Out of Luck), since it's implementation dependent. If this doesn't work, and you are still interested in a (non-portable) way of doing the deed, try the following, and tell us what you get: CPP / C++ / C Code:
You should also tell us what compiler you are using, since it very well might make a difference. Regards, Dave Footnote: The C standard says that "A bit-field shall have a type that is a qualified or unqualified version of _Bool, signed int, unsigned int, or some other implementation-defined type." So, whether a compliant compiler even allows having a bit field declared as an unsigned char is implementation-dependent. (And of course, regardless of the language of the Standard, some compilers try harder than others to be compliant.) |
|
#6
|
|||
|
|||
Re: need urgent helpCPP / C++ / C Code:
Last edited by LuciWiz : 20-May-2008 at 06:48.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
Recent GIDBlog
Welcome to Baghdad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Very Very Very Very Urgent Help | Rosemary | C++ Forum | 3 | 18-Apr-2007 05:05 |
| Urgent Help Required | mkjuly | C Programming Language | 0 | 14-Oct-2006 08:12 |
| [GRAPHICS] - SymbolDesignerTool - URGENT HELP PLS | metan | Java Forum | 0 | 15-Mar-2006 00:32 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The