[omniORB] SystemException::NP_minorString() returns 0

Alex Tingle alex.omniorb at firetree.net
Sun Sep 26 00:56:36 BST 2004


I wrote:
> > I expect to have to test the result of a call when it returns
> > `char*', but I'd usually expect functions that return `const char*'
> > to always give me something I can use.

Rene Jager <renej_frog at users.sourceforge.net> wrote:
> I'd prefer a string with the minor code instead of "unknown". These
> things can be done easily with small inline functions (as I do now).
> That way you can also hide the use of NP_* functions.

Hmm. This is hard to do. The function returns `const char*', so the
caller would not expect to be responsible for freeing the return value's
memory. That makes it difficult to manufacture descriptive strings on
the fly.

You can easily overcome this problem by returning a class (like
std::string), but then you're adding to the complexity (if you write
your own class) or depenencies (if you use the STL).

> Returning not a 0 ptr would make it harder to detect for the prgrammer
> that it is an unknown minor code.

That's just not true. An empty string is just as easy to test for:

  if(minor[0])...
  if(::strlen(minor)==0)...

In any case, this accessor method is the wrong place for testing whether
a code is known. A special `bool NP_hasRecognisedMinorCode()' method
would be more appropriate.

-Alex

-- 
:: alex tingle
:: 58 kings way, harrow, mddx. uk. HA1 1XU
:: alex.tingle AT firetree.net  +44-7901-552763 



More information about the omniORB-list mailing list