This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

bit manipulation functions


Gang,

It seems that our bit manipulation functions are more
restrictive than implied by the language of the standard 
(where I only have a PDF of the May 2004 working draft of
the newest standard).  Anyway, the language for IBSET is

------------------------------------------------------
13.7.49   IBSET(I, POS)

  Description.  Sets one bit to one.

  Class.        Elemental function.

  Arguments.
    I           shall be of type integer.
    POS         shall be of type integer. It shall be nonnegative and 
                less than BIT_SIZE(I).

  Result Characteristics.  Same as I.

  Result Value.  The result has the value of the sequence of bits of 
                 I, except that bit POS is one.
------------------------------------------------------

Note I and POS "shall be of type integer".  The kind parameter is
not specified.  We currently restrict POS to default integer
kind with an implied restriction of I to default integer kind.
The restriction is in check.c

try
gfc_check_ibset (gfc_expr * i, gfc_expr * pos)
{

  if (type_check (i, 0, BT_INTEGER) == FAILURE
      || type_check (pos, 1, BT_INTEGER) == FAILURE
      || kind_value_check (pos, 1, gfc_default_integer_kind) == FAILURE)
    return FAILURE;

  return SUCCESS;
}

If I remove the kind_value_check() from the above.  The attached
program produces the following output:
kargl[205] ./bits
  8 16 32 64
  6  6  6  6
 20 20 20 20
   12 4108 4108 4108
This agrees with both G77 and NAG's Fortran 95 compiler.  So, do
we want to loosen the restrictions?

-- 
Steve

Attachment: bits.f
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]