If I have, for example, a pointer to an array of unsigned ints, how can I make bitmaps of them, for I could then call:
Code: Select all
array[i].bitx=1; // or 0
(I have a bitmap structure type of the size of unsigned int.)
Code: Select all
array[i].bitx=1; // or 0
Code: Select all
// solar, this next line is not for you
typedef int *bit_vector;
bit_vector create_bit_vector(int bits) {
return (bit_vector)malloc((bits + 7) / 8);
}
int get_bit(bit_vector v, int bitno) {
// do magic
return v[bitno / 8] >> (bitno % 8);
}
int set_bit(bit_vector v, int bitno, /*bool*/int on) {
// do magic
register int byteno = bitno / 8;
v[byteno] = (v[byteno] & (1 << (bitno % 8))) | (on << (bitno % 8));
}
void free_bit_vector(bit_vector v) {
free(v);
}
If you intend to make an array of structs:OSMAN wrote: Hi.
If I have, for example, a pointer to an array of unsigned ints, how can I make bitmaps of them, for I could then call:?Code: Select all
array[i].bitx=1; // or 0
(I have a bitmap structure type of the size of unsigned int.)
Code: Select all
struct nice_struct{
int bitx:1, bity:1;
int value:3, valuetoo:3;
};
nice_struct array[42];
int main() {
array[0].bitx = 1;
}
Allowed? Actually, the standard requires vector<bool> to optimize to a bit vector. However, a vector<bool> does no longer behave like a standard vector, which is why it has fallen from grace some time before.Candy wrote: You could try (if you actually use a C++ compiler) to make an array of bools and to see whether it optimizes them to a bit vector (is that allowed Solar?).
That's exactly my point, that it was NOT a vector. It's an array:Solar wrote:Allowed? Actually, the standard requires vector<bool> to optimize to a bit vector. However, a vector<bool> does no longer behave like a standard vector, which is why it has fallen from grace some time before.Candy wrote: You could try (if you actually use a C++ compiler) to make an array of bools and to see whether it optimizes them to a bit vector (is that allowed Solar?).
A good link on what you should know about vector<bool>. It is deprecated, and future standard versions might no longer have this specialization (which means your code would suddenly break when compiled with a newer C++ library.)
Code: Select all
bool array[256];