=?ISO-8859-2?Q?Re: Antwort: [AGENT++] SNMP++/Agent++ on Windows (VC++) and the new operato= r?=

maom_onet at poczta.onet.pl maom_onet at poczta.onet.pl
Fri Feb 25 15:13:56 CET 2005


Comments below.

Użytkownik Jens Engel <Jens.Engel at marconi.com> napisał:
>Another note to Marek\'s comments:
>
>Well, the core problem is not that SNMP++ checks for NULL pointers after
>new() (if you meant that).
>I wouldn\'t use a try-catch block for std::bad_alloc in most places were
>objects are allocated.
>The core problem is that SNMP++/Agent++ does not use an exception-safe
>programming style [1, 2] (in most cases).

Of course, I am aware that C++ with and without exceptions are two *very* different programming languages, and that exceptions require a different approach to avoid memory and other resources leaks. (In fact, I have written quire serious code in both styles.) SNMP++/Agent++ are written in the old C++ and this is (probably) impossible to switch to the new, exception-based approach in a reasonable time. In fact, such a dramatic change in standard immediately questioned all "obsolete" C++ code, from the "pre-exceptional" era.

What I just meant by my warning is that some users could be unaware of the behavior of the new operator. Some time ago I checked this (to verify that SNMP++ would work ok) and I seemed that VC++'s new did not throw by default - which was of course wrong - I do not remember why I was misguided, however, as you read the docs you will see that there is some "disorder". For example, the behavior is defined by *library link order*, which is quite unexpected (the way the code works does not depend on the code itself).

>[2] Herb Sutter, "Exceptional C++",
>http://www.gotw.ca/publications/xc++.htm (on exception safe programming
>styles)

If you were able to read and completely understand this book, then my congratulations. I had given up after a while. In my opinion, this book is a proof that C++ is too complex for any serious programming. Unless your company can afford to hire very smart programmers (this is my private opinion; I am not going to start any war).

>P.S.: Just an idea to "reverting to the nothrow new allocation scheme".
>Most C++ compilers allow to disable exceptions.
>I would assume that no std::bad_alloc is thrown when exceptions are
>disabled (and hopefully a NULL pointer is returned).

Yes, if you can do this, then this should work. In my personal case, I mix unmanaged C++ code with .NET C++ code (I have not tested possible effects of disabling exceptions; I can only say that it causes anxious compiler warnings with suggestions to enable it back).

Best regards,

Marek



More information about the AGENTPP mailing list