On 2015-08-27 6:12 AM, Noob wrote:
> Hi,
>
> I'm looking for a way to work with 1-byte integers in a portable way.
> Right now, I know of INTEGER(INT8) or a CHARACTER.
It is an interesting question. Quite a few algorithms are written in
terms of manipulating "octets", and I find that doesn't map neatly
across to Fortran's intrinsic types.
There's also INTEGER(C_INT8_T), pulling C_INT8_T out of ISO_C_BINDING.
Depending on what you want to do, note that a character isn't an
integer. I think a reasonable guideline is that if you want an integer,
then use an integer - I would avoid (or isolate) if possible any games
where you store an object of one type in another object of different type.
What's the
> likelihood of INTEGER(INT8) not actually being available somewhere?
There is a 100% chance that it will *not* be available somewhere (the
world is a big place), but do you really care? On Fortran processors
that support the language revision that introduced INT8 (F2008), there's
a reasonable chance that they will support INT8.
Note that Fortran integers are always signed though. Depending on what
you want to do, that may complicate things. For example, algorithms
written in terms of octets often assume unsigned integer arithmetic on
those octets (or a group of octets) modulo the integer size.
Algorithms written in terms of octets also do a lot of bit manipulation
stuff. Perhaps this is a little esoteric given the Fortran processor
landscape of today, but note that the STORAGE_SIZE of an integer does
not have to be the same as the BIT_SIZE, and that the bit pattern that
results from a negative integer is processor dependent.
I'm interested in hearing the approach that others use in this area.