--- In [email protected], "Paul Herring" <[EMAIL PROTECTED]> wrote: > > On Mon, Aug 4, 2008 at 4:46 PM, thides <[EMAIL PROTECTED]> wrote: > > --- In [email protected], "Brett McCoy" <idragosani@> wrote: > >> > >> A bug was found in some C++ code recently, in my company. This code is > >> used on server software for when we have MX lookups for sending mail. > >> It was found by a customer (*yikes*) after they had applied a Sun > >> recommended patched cluster on their Solaris server: > >> > >> if (resState == NULL) { > >> resState = new __res_state; //__res_state is a struct > > *snip* > > > > I thought new and structs were not to be used together. > > structs in C++ are essentially just classes with the default of public > instead of private. Those without member functions are called PODs. > (plain old data) > > How else would you dynamically assign a struct? (Hint: malloc() is not > the correct answer here... ;) ) > *snip*
After doing some old textbook reading I think that its constructors and destructors that structs can't use. As for malloc() and structures according to my reading (ten year old books) can be used together in C as the only way to allocate memory on the heap is malloc() - new is a C++ keyword. With that in mind, the code for allocation using malloc() and structures really looks messy opposed to the clean and trim new. My preference in C++ would most definitely be new. Steve
