SNMP++ const correctness

Frank Fock Frank.Fock____t-online.de
Thu May 3 00:52:11 CEST 2001


Hi Martin,

Please find my comments inline:

janzen wrote:

> Another new SNMP++ / Agent++ user here, in the process of converting
> from UCD-SNMP (er, NET-SNMP).  First, many thanks to Frank and
> company!!  Writing an agent with this thing is _much_ easier than with
> other C-based libraries.
>

"Simple" was the first objective when I started work on AGENT++.
Thanks for the praise :-D

>
> One comment about the SNMP++ headers:  Many methods that ought to be
> const, esp. the get_printable() methods, are not.  This causes a large
> number of spurious warning messages, or forces callers to add lots of
> ugly const_cast<>'s, or makes them break their own const correctness.
>

I agree.

>
> I expect that a method such as OctetStr::get_printable() is not const
> because it modifies the internal OctetStr::output_buffer pointer -- and
> the 1996-era C++ compilers used for the original HP SNMP++
> implementation would have been unlikely to have implemented the
> 'mutable' keyword.  However, nowadays I'd hope that this is supported by
> any reasonable compiler.
>

Some years ago I asked Peter Mellquist why SNMP++v2.x is not
const correct. He replied that he wrote it const correct in the first
place but HP asked him to change it as it is today, because other
HP source did not work with const.
Jochen and me did not change that behaviour in SNMP++v3.x
because we wanted to make it as easy as possible to switch
from SNMP++v2.x to SNMP++v3.x.
Nevertheless I implemented some wrapper classes for the
most commonly used SNMP++ classes in AGENT++.
They are called Vbx, Oidx, etc. and they are const correct to
some extend.

>
> In good open-source fashion, I'm not asking Frank or anyone else to fix
> this for me; I have no problem doing it myself and sending along the
> patches or what have you.  But first...
>
> 1) If I were to make a pass through this code and to try and make it at
> least somewhat more const correct, would this be a good thing?  Can
> anyone think of ways in which this might break existing, working code?

Yes and may be but I do not think so.

>
>
> 2) Does anyone _not_ have a 'mutable' keyword?  I'm fairly certain that
> g++, MSVC++, and HP aCC all support this by now; are there any widely
> used compilers which still do not?  (Lack of 'mutable' would turn a
> relatively simple task into an #ifdef nightmare, and would very much
> dampen my enthusiasm for this exercise...)
>

I will check this out within the next days. Results will be posted to
the list...

>
> 3) Any reasons why get_printable() et al. shouldn't return a 'const char
> *' rather than a 'char *'?  Would it break things for anyone if I were
> to fix this while I'm at it?
>

Don't think so, it may only be a matter of portability.

Best regards,
Frank




More information about the AGENTPP mailing list