Re[2]: [Dev-C++] using char* as bitfield
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-09-29 15:08:34
|
Yes, it is possible to do with char*
char* alloc_bits(unsigned bits) {
char *bits;
unsigned size;
size =3D (bits+7)/8;
bits =3D malloc(size);
if (bits) memset(bits,0,size);
return bits;
}
void set_bit(char* bits,unsigned bit) {
array[bit/8] |=3D 1 << (bit&3);
}
char *mybits;
mybits =3D alloc_bits(1000);
if (mybits) set_bit(mybits,117);
/Per W
On Mon, 29 Sep 2003, [ISO-8859-15] Christian Sch=E4fer wrote:
> hi David,
>
> > Do you know how many bits you will need at compile time?
> yes, I do.
>
> > If you then use a bitset. It is part of the STL.
> I should have said, that I am doing this in c not in c++.
>
> > If you don't then you can use vector<bool> and hope your
> > compiler vendor
> > optimized it for space.
>
> it should be possible to use a char*, right?
>
>
>
> gruss
> /Christian mailto:ca...@kr...
>
> ---
>
>
> I propose that the following character sequence for joke markers:
>
> :-)
>
> 19-Sep-82 11:44 Scott E Fahlman
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|