CORBA style was: [omniORB] CORBA::string_alloc(len) problem
Mark D. Landry
mdlandry@lincoln.midcoast.com
Thu, 15 Jul 1999 17:57:00 -0400
Is there any wonder why developers swear off C++ and CORBA for more
accessible technologies like Java and VB? You'd need a friggin' master's
degree in CS to understand this discussion. I've got one and it still
doesn't make much sense. What ever happened to the art of writing code that
others can read (and compilers can translate)?
Sorry, I know this is off topic for this group but unless CORBA becomes more
usable by the typical business programmer it will fade into the sunset like
so many other good technologies. One look at a mesage like this and most
programmers' eyes glaze over. This may explain why we see so many
unsubscribe messsages sent to the list.;-)
(Bruce, no offense intended.)
Bruce Visscher wrote:
> Just a nit.
>
> Stephen Coy wrote:
> >
> > You probably need to do something like:
> >
> > char * myStr = CORBA::string_alloc(100);
> > String_var myStrVar = myStr;
>
> I assume you meant CORBA::String_var.
>
> Please don't do this. This is copy initialization. According to the
> ISO C++ standard this is defined to create a temporary using the
> converting constructor, CORBA::String_var::String_var(char*), then to
> invoke the copy constructor from the temporary and finally to invoke the
> String_var destructor on the temporary. This winds up doing a strlen on
> unitialized memory in the copy constructor.
>
> Compilers are allowed to optimize away the temporary. Most will.
> However, the DEC C++ compiler on the VAX won't (it always does on Alpha
> VMS; I assume it does on Tru64 Unix). Therefore, you will only have
> problems on certain platforms (maybe just the VAX?). But if you really
> want to be portable you should use direct initialization syntax:
>
> CORBA::String_var myStrVar(myStr);
>
> I realize there are even examples using copy initialization syntax like
> the above in the CORBA standard. IMHO, the (CORBA) standard is wrong.
>
> Bruce Visscher