Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > bit field with Arrays

Reply
Thread Tools

bit field with Arrays

 
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      07-21-2004
hack_tick <(E-Mail Removed)> spoke thus:

> struct Tmp
> {
> int iVar[20] : 1; // each element of Aray having size as 1-BIT
> }


> any suggestions ???


Yes - vector<bool>.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
 
Reply With Quote
 
 
 
 
Wouter Lievens
Guest
Posts: n/a
 
      07-21-2004
"hack_tick" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> hi there
> I was looking for some way to use bit field with Arrays
> something similar to
>
> struct Tmp
> {
> int iVar[20] : 1; // each element of Aray having size as 1-BIT
> }
>
> it is possible ??
> any suggestions ???
>
> -regards


The standard template library uses template specialisation for vector<bool>,
I think. You can use this explicitly as the std::bitset class.


 
Reply With Quote
 
 
 
 
hack_tick
Guest
Posts: n/a
 
      07-21-2004
hi there
I was looking for some way to use bit field with Arrays
something similar to

struct Tmp
{
int iVar[20] : 1; // each element of Aray having size as 1-BIT
}

it is possible ??
any suggestions ???

-regards


 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      07-21-2004

"hack_tick" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> hi there
> I was looking for some way to use bit field with Arrays
> something similar to
>
> struct Tmp
> {
> int iVar[20] : 1; // each element of Aray having size as 1-BIT
> }
>
> it is possible ??


No.

> any suggestions ???
>


Use std::bitset instead

#include <bitset>

struct Tmp
{
std::bitset<20> iVar;
};

john


 
Reply With Quote
 
tom_usenet
Guest
Posts: n/a
 
      07-21-2004
On Wed, 21 Jul 2004 19:08:23 +0530, "hack_tick" <(E-Mail Removed)>
wrote:

>hi there
>I was looking for some way to use bit field with Arrays
>something similar to
>
>struct Tmp
>{
> int iVar[20] : 1; // each element of Aray having size as 1-BIT
>}
>
>it is possible ??


Not like that, no.

>any suggestions ???


struct Tmp
{
std::bitset<20> iVar;
};

If you need Tmp to be a POD type, you could code your own POD version
of bitset. OTOH, bitset is close enough to a POD type to work with
memcpy with normal compilers.

Tom
 
Reply With Quote
 
Wouter Lievens
Guest
Posts: n/a
 
      07-21-2004
"hack_tick" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> hi there
> "Christopher Benson-Manica" <(E-Mail Removed)> wrote in message
> news:cdlr74$2n5$(E-Mail Removed)...
> > hack_tick <(E-Mail Removed)> spoke thus:

> [...]
> > Yes - vector<bool>.

>
> thanks for the suggestion, but sorry i didnt mentioned in my earlier post
> that
> I m working on Symbian Series 60 platform, and the struct is a part of
> protocol which i m using over Bluetooth for communication which is already
> tooooo heavy so i was looking for some way to reduce the size by using
> bitfield, also Symbian Series 60 have few bugs and issued with STL so i
> usually tend to avoid STL with my applications.
>
> regards


Then you'll have to write it yourself - it's not hard.


 
Reply With Quote
 
hack_tick
Guest
Posts: n/a
 
      07-21-2004
hi there
"Christopher Benson-Manica" <(E-Mail Removed)> wrote in message
news:cdlr74$2n5$(E-Mail Removed)...
> hack_tick <(E-Mail Removed)> spoke thus:

[...]
> Yes - vector<bool>.


thanks for the suggestion, but sorry i didnt mentioned in my earlier post
that
I m working on Symbian Series 60 platform, and the struct is a part of
protocol which i m using over Bluetooth for communication which is already
tooooo heavy so i was looking for some way to reduce the size by using
bitfield, also Symbian Series 60 have few bugs and issued with STL so i
usually tend to avoid STL with my applications.

regards


 
Reply With Quote
 
Wouter Lievens
Guest
Posts: n/a
 
      07-21-2004
"tom_usenet" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> On Wed, 21 Jul 2004 19:08:23 +0530, "hack_tick" <(E-Mail Removed)>
> wrote:
>
> >hi there
> >I was looking for some way to use bit field with Arrays
> >something similar to
> >
> >struct Tmp
> >{
> > int iVar[20] : 1; // each element of Aray having size as 1-BIT
> >}
> >
> >it is possible ??

>
> Not like that, no.
>
> >any suggestions ???

>
> struct Tmp
> {
> std::bitset<20> iVar;
> };
>
> If you need Tmp to be a POD type, you could code your own POD version
> of bitset. OTOH, bitset is close enough to a POD type to work with
> memcpy with normal compilers.
>
> Tom


What is POD?
Like RAII?


 
Reply With Quote
 
Sumit Rajan
Guest
Posts: n/a
 
      07-21-2004

"Wouter Lievens" <(E-Mail Removed)> wrote in message
news:40fe747e$0$3971$(E-Mail Removed)...

> What is POD?
> Like RAII?


Plain Old Data.

Try:
http://www.parashift.com/c++-faq-lit....html#faq-26.7

Regards,
Sumit.
--
Sumit Rajan <(E-Mail Removed)>


 
Reply With Quote
 
tom_usenet
Guest
Posts: n/a
 
      07-21-2004
On Wed, 21 Jul 2004 15:49:55 +0200, "Wouter Lievens"
<(E-Mail Removed)> wrote:

>"tom_usenet" <(E-Mail Removed)> schreef in bericht
>news:(E-Mail Removed).. .
>> On Wed, 21 Jul 2004 19:08:23 +0530, "hack_tick" <(E-Mail Removed)>
>> wrote:
>>
>> >hi there
>> >I was looking for some way to use bit field with Arrays
>> >something similar to
>> >
>> >struct Tmp
>> >{
>> > int iVar[20] : 1; // each element of Aray having size as 1-BIT
>> >}
>> >
>> >it is possible ??

>>
>> Not like that, no.
>>
>> >any suggestions ???

>>
>> struct Tmp
>> {
>> std::bitset<20> iVar;
>> };
>>
>> If you need Tmp to be a POD type, you could code your own POD version
>> of bitset. OTOH, bitset is close enough to a POD type to work with
>> memcpy with normal compilers.
>>
>> Tom

>
>What is POD?
>Like RAII?


In addition to what Sumit posted, the key thing about PODs is that you
can memcpy them around, which makes them easy to serialize, etc.

Tom
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
1.Enter space bar for field names and save the field.The field shoud not get saved and an alert should be there as"Space bars are not allowed" Sound Javascript 2 09-28-2006 02:43 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments