compiler : visual c++ 2005
os : win7 64bits
The more I study about our source codes, the more dense fogs surround my head.
According to what I know, memset can't be used to initialize POD
This is the snippet of our codes(The problem of encapsulation?
there are too many public or protected data members in our codes without any
special reason--except of "this is convenience", I am tired to refine this).
//non POD type
struct MessageQueryTester
{
public:
void querySupportModel() {}
unsigned int supportedModelSize() { return 0; }
const char* supportedModel(unsigned int index) { return "keke"; }
void retrieveModelDetail(const char* model_name) {}
public:
/// the index of received message
unsigned int msg_index_;
/// the illegal args size error of constructor
bool constructor_args_size_error_;
/// the vendor name
boost::shared_ptr<std::string> vendor_name_;
/// the input argument position of vendor name of constructor
enum { VENDOR_ARG_POSITION };
/// the input argument position of xpath of constructor
enum { XPATH_ARG_POSITION = 1 };
/// the minimum input argument size of constructor
enum { MINIMUM_ARG_SIZE = 2 };
/// the character array size of result value
enum { RESULT_STR_LENGTH = 50000 };
/// the return value of cslim tester
char result[RESULT_STR_LENGTH];
private:
/// the supported model of request vendor
vector<boost::shared_ptr<std::string> > support_models_;
};
//create and initialize
void* initialize()
{
MessageQueryTester* self = (MessageQueryTester*)malloc(sizeof(MessageQueryTester));
memset(self, 0, sizeof(MessageQueryTester));
return self;
}
Why using malloc and void*?The answers I got
"because the other do it like this"
But this codes already lingering about one year and nothing happen(?),
I thought this may lead to undefined behavior if I use memset on non POD type.
Thanks