[omniORB] constant to large for long

Duncan Grisby dgrisby@uk.research.att.com
Mon, 15 Jan 2001 16:50:30 +0000


On Monday 15 January, erberj@post.ch wrote:

> on VMS omniidl complains about the following:
> 
> const long nullDateHigh = -x80000000
> 
> with
> 
> Integer Literal is to large for long. According to the corba book, this
> should work.

My original reading of the IDL specification was that it is illegal,
although the wording is confusing, and possibly contradictory. Now I'm
not so sure. The relevant paragraph says:

  "If the type of an integer constant is long or unsigned long, then
   each subexpression of the associated constant expression is treated
   as unsigned long by default, or a signed long for negated literals
   or negative integer constants. It is an error if any subexpression
   values exceed the precision of the assigned type, or if a final
   expression value exceeds the precision of the target type."

Later on, it says:

  "...Unary (+ - ~) and binary (* / % + - << >> & | ^) operators are
   applicable in integer expressions."

I would interpret the constant above as a unary expression, equivalent
to

  const long nullDateHigh = - (0x80000000);

In that case, the subexpression 0x80000000 exceeds the precision of
long. This is regardless of the fact that the negated version of the
sub-expression _does_ fit in long.

I think it all hinges on the intended meaning of the word "assigned"
in the first quote above. What is the "assigned type"?  Is it the same
as the "target type"?  If it _is_ the same, the omniidl is right to
reject the IDL. If it's some other thing, then perhaps omniidl is
wrong.

To get the constant you need in a way which is guaranteed to be OK,
use

  const long nullDateHigh = -0x7fffffff - 1;


Cheers,

Duncan.

-- 
 -- Duncan Grisby  \  Research Engineer  --
  -- AT&T Laboratories Cambridge          --
   -- http://www.uk.research.att.com/~dpg1 --