[omniORB] create_union_tc with discriminator type long

Duncan Grisby duncan@grisby.org
Fri Sep 6 15:54:01 2002


On Tuesday 3 September, "Clemens Fischer" wrote:

> i've got a problem with omniORB4 beta2 under NT.
> The following code throws BAD_PARAM from create_union_tc():

This is unpleasant. The problem is due to a compiler bug in Visual C++
6. The union typecode has to be able to hold the discriminators for
the members, whatever the discriminator type, so it uses a long long
(on platforms that have it), to make sure that all possible values can
be held. With smaller discriminator types, it checks that the
discriminator values are within the range of the type. The bug is that
VC++ incorrectly compiles literal long longs less than or equal to -
2^32, so they come out large and positive. The code is essentially
doing

  if (discriminator < -2147483648)
    throw CORBA::BAD_PARAM(...);

but the compiled code comes out as if it said

  if (discriminator < 2147483649)
    throw CORBA::BAD_PARAM(...);

hence the exception.

I've checked in a fix that replaces the literal -2147483648 with
-2147483647 - 1, and it works fine now.

This compiler bug will also affect the generated code for IDL const
long longs. If you have large negative consts in your IDL, they won't
come out right on Windows. Can someone with VC7 check to see if it
still has the bug?

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan@grisby.org     --
   -- http://www.grisby.org --