I'm trying to initialize a static block of memory to all zeros using (essentially) the following code:
[CODE=cpp]
#define NUM_BYTES 2048
typedef unsigned int uint;
class SomeClass {
protected:
static const uint* some_block();
public:
// more methods and such...
};
const uint* some_block() {
static bool isUninit = true;
static uint block[NUM_BYTES];
if( isUninit ) {
uint* at = block + NUM_BYTES;
while( at-- > block) *at = 0;
isUninit = false;
}
return block;
}
[/CODE]
My question is if there is an easier way to do this initialization, i.e. without using isUninit. I don't think there is any guarantee that the block will be initialized to all zeros, but is there a way to avoid having isUnint?
Thanks
[CODE=cpp]
#define NUM_BYTES 2048
typedef unsigned int uint;
class SomeClass {
protected:
static const uint* some_block();
public:
// more methods and such...
};
const uint* some_block() {
static bool isUninit = true;
static uint block[NUM_BYTES];
if( isUninit ) {
uint* at = block + NUM_BYTES;
while( at-- > block) *at = 0;
isUninit = false;
}
return block;
}
[/CODE]
My question is if there is an easier way to do this initialization, i.e. without using isUninit. I don't think there is any guarantee that the block will be initialized to all zeros, but is there a way to avoid having isUnint?
Thanks
Comment