[omniORB] Allocation of memory for sequence "vars"

Visscher, Bruce VISSCHB at RJRT.com
Tue Sep 21 14:28:53 BST 2004


> I have a very simple sequence that I am allocating and would like to
> check that the allocation was successful.
> 
> The IDL is :
> 
>     interface SEQ {
>     
>         enum ABC { want, more };
>         typedef sequence<ABC> ABCseq;
>     };
> 
> And the code (C++) I wish to convert is:
>  
>    SEQ::ABCseq_var me = new SEQ::ABCseq();
>     if(me == NULL) printf("ERROR\n");

This is actually wrong for 2.5 reasons. :-)

The main reason is that standard C++ will never set the null pointer to 0, but 
will instead throw an exception (std::bad_alloc, IIRC...In any case it should
be derived from std::exception so you can catch(std::exception&)).  So, the
printf should never execute anyway (some compilers might have a backwards
compatibility flag to cause new to return 0 instead).

The other reason is that the var type would be initialized to nil, not 0. So,
to check whether an object has been allocated you should use CORBA::is_nil(me)
instead.

The 0.5 reason is that the null pointer is spelled "0" in C++, not "NULL".

> 
> When I compile this, using OMNI, I get an error on the "me == 
> NULL" test
> to the effect that no such comparison is available.

....which is a good thing since this isn't correct code.

-----------------------------------------
CONFIDENTIALITY NOTE:  This e-mail message, including any  attachment(s),
contains information that may be confidential,  protected by the attorney-
client or other legal privileges, and/or  proprietary non-public
information.  If you are not an intended  recipient of this message or an
authorized assistant to an intended  recipient, please notify the sender by
replying to this message and  then delete it from your system.  Use,
dissemination, distribution,  or reproduction of this message and/or any of
its attachments (if  any) by unintended recipients is not authorized and
may be unlawful.




More information about the omniORB-list mailing list