1

I was using the zext() function with Sun Studio Fortan compiler, to transform integer(kind=1) to integer(kind=4), in order to be able to manipulate bits with ibits() function.

eg :

! Accessing the most significant bit of a byte status

integer(kind=1) :: status
integer         :: msb

msb = ibits (zext (status), 7, 1)

It seems that this function is not part of gfortran compiler.

Is there an equivalent function available in gfortran ?

  • Please learn how to use the code and other formatting. – Vladimir F Героям слава Sep 28 '15 at 14:31
  • 1
    See also https://groups.google.com/forum/#!topic/gg95/lHjsbCms_7g BTW if you believe kind=1 is one byte and kind=4 is 4 bytes, it is not always necessarily so http://stackoverflow.com/questions/3170239/fortran-integer4-vs-integer4-vs-integerkind-4 – Vladimir F Героям слава Sep 28 '15 at 14:35
  • gfortran allows any kind of integer as the argument to ibits as long as it matches the return type. If you have `status` and `msb` of the same kind, you don't need to convert it. Also, as pointed out above, `kind=1` doesn't always mean 1 byte. Better to use the constant `int8` from the `iso_fortran_env` to get a 1 byte int e.g. `integer(kind=int8) :: status, msb` – casey Sep 28 '15 at 14:46
  • you can of course fairly trivially write your own `zext` function if you need it – agentp Sep 28 '15 at 14:59
  • 1
    @casey - not just gfortran, but Fortran. A standard conforming compiler must support all standard intrinsic functions acting on all supported kinds of appropriate data types. – Ian Bush Sep 28 '15 at 16:50
  • @IanBush true. I was lazy and only checked the gfortran docs because that is what he was asking and didn't verify what the standard had to say about it. Thanks for adding the clarification. – casey Sep 28 '15 at 16:52

0 Answers0