Devaraj posted:
Thanks.. what if i know that the structure always contains 5 chars , 2
long and some date data types..It will never change the datatypes as it
is constantly fetching the rows from a table and does some logic..after
processing the first row, it gets into the next row in a while loop.
here i would like to clear out the contents of the structures before
fetching the second record. What abt usung 9 memset's for ech
member..is that possible..please help!
Coincedently, there's a thread over on comp.lang.c++ very similar to
this...
I'm not sure exactly what you're trying to do. If you want to set an object
to all-bits-zero, then simply do:
memset(&obj,0,sizeof obj);
If you would like to set an object to its default value, then... hmm...
maybe the following would be a start. If your compiler supports "inline",
then:
/* FILE BEGIN: clearer.h */
#define DEFINE_CLEARER(Type) \
inline void Clear(Type *const p) \
{ \
static Type const blank_obj = {0}; \
\
*p = blank_oj; \
}
/* FILE END: clearer.h */
Then just include that header in your source file, and pre-define the
clearer function:
DEFINE_CLEARER(MyType)
int main()
{
MyType obj;
Clear(&obj);
}
This won't work for arrays for two reasons:
(1) The function parameter will come out as "int[5] *const p" rather
than "int (*const p)[5]".
(2) You can't assign to an array (although we could overcome this with
memcpy).
(Not to wave the C++ flag, but if you could write even one of the source
files in C++, there'd be a very simple solution.)
--
Frederick Gotham