Re: BOZ literal constants, a puzzle for us Standard-loving types.



Brooks Moses wrote:

(snip)

Note that, in F2003, this will also apply to INT(z'FFFF8000'). It's not just something that happens with DATA statements.

I thought so, but tried it anyway.

Question to my fellow J3 Committee members: Did we really mean to outlaw this (it has an obvious meaning: stuff the 32 bits that FFFF8000 hex represents into a 32 bit integer and "damn the torpedo's".

g77 accepts it without even warning about it, so this probably means most compilers accept it (g77 was rather late to the game and, consequently, a follower of fashion).

I wouldn't mind it as a warning, especially if run time overflow
is not detected and trapped.

IIRC, g77 is doing rather weird things with it, actually, since it's interpreting the z'FFFF8000' as an integer constant and then converting it. I wouldn't be surprised to find that it's assigning it to an 8-byte integer and then simply wrapping it without throwing an error when it gets assigned to i.

My interpretation would be that the standard isn't, per se, outlawing this _as an extension_. The behavior when an integer is out of range is undefined, and I think it would not be amiss for a compiler to adjust its range-checking to allow for this usage as a special case, considering assignments from a BOZ-literal to an integer to be out of range only when there are too many bits.

It could even allow it when there are too many bits, as far as I know.

But, yeah, I would agree that this is a defect in the standard, that integer constants -- which are how most people store bitwise things! -- don't seem to follow the "treat BOZ-literals as a bitwise representation" rule.

I could argue both ways, but in terms of bitwise operations it makes
sense. I could probably live with -Z'00008000', too. It makes
less sense for bitwise operations, but for integer operations it will
work even for different BIT_SIZE, though only in twos complement.
I believe the only ones complement machines in production are 36 bit,
so in that case you lose twice.

-- glen

.



Relevant Pages

  • Re: puzzle
    ... Most modern languages do support bitwise operations on integers. ... Perl has bitwise xor. ...
    (comp.programming)
  • Re: Differences between VB6 and VB.Net causing problem
    ... Integer and Long are bitwise numerics. ... Oh, and for the record, VB6 and VB.NET do NOT store 0 and -1. ... What do you get when you try to store True to a Decimal type? ... You can't do bitwise operations directly on a Decimal type: ...
    (microsoft.public.vb.general.discussion)