SNMP++ const correctness

janzen janzen____pixelmetrix.com
Wed May 2 06:02:32 CEST 2001


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.

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 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.

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?

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...)

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?

Thanks...

--
Martin Janzen
janzen at pixelmetrix.com



More information about the AGENTPP mailing list