[omniORB] CORBA::String operator = (char *)
Dietmar May
dcmay@object-workshops.com
Wed, 29 Jul 1998 09:52:21 -0700
Lio,
This is the expected behavior, and is in accordance with the CORBA spec,
sec 16.7 (straight from the CORBA standard):
Note that a static array of char in C++ decays to a char*, so care must
be taken when
assigning one to a String_var, since the String_var will assume the
pointer
points to data allocated via string_alloc, and thus will eventually
attempt to
string_free it:
// C++
// The following is an error, since the char* should point
// to data allocated via string_alloc so it can be consumed
String_var s = "static string";// error
// The following are OK, since const char* are copied,
// not consumed
const char* sp = "static string";
s = sp;
s = (const char*)"static string too";
> Is it correct, that the operator = of CORBA::String differs when using
a
> (char *) compared to a (const char *)? I checked the source and found
> that in the 1st case, the string is not copied. This is a bit annoying
> when using stuff like:
>
> CORBA::String str;
> str = "foo";
>
> In this case the "foo" is a (char *) (could not believe this 1st, but
I
> checked it with several compilers incl. g++) and you get into trouble
if
> you don't change it to:
>
> str = (const char *) "foo";
>
> because CORBA::String will coredump when deleting "foo" ... any
> suggestions? Or is this just my mistake?
Regards,
Dietmar May
Software Architect
Object Workshops, Inc.
dcmay@object-workshops.com