CORBA style was: [omniORB] CORBA::string_alloc(len) problem

David Riddoch djr@uk.research.att.com
Fri, 16 Jul 1999 14:20:46 +0100 (GMT)


On Fri, 16 Jul 1999, Doug Anderson wrote:

> I believe you can also do the following and consume it:
> 
> CORBA::String_var SomeString = (char *)string_alloc(100);
> SomeString[0] = 'f';
> SomeString[1] = 'o';
> SomeString[2] = 'o';
> SomeString[3] = '\0';

This one is wrong for the same reason as the original posting.

> If the cast were (const char *), it would deep copy the alloc.

Yes, if the arg is (const char*) we do copy, but in this case that would
be a disaster too, because we have not initialised the string.

In fact if we do have a valid string on the right hand side, if the
temporary is not optimised away (as on the VAX) then the following would
lead to the string being copied twice:

String_var foo = (const char*) "hello";


David