From: dpb on
dpb wrote:
....

> I don't believe the above is guaranteed to work by Standard ...

Actually, I'm sure it's not... :)

--
From: glen herrmannsfeldt on
Uno <merrilljensen(a)q.com> wrote:
(snip on KINDs)

> I wanted to ask this back in the thread with the hollerith constants,
> where the scheme was somewhat dependent on having a 4-byte integer.

> Is there a portable to ask for one with a call to selected_int_kind?

In C, sizeof() is, by definition, in units such that sizeof(char) is 1.
A C char is at least eight bits, but could be larger.

Since Fortran added CHARACTER in Fortran 77, and KIND not until
later, using SELECTED_INT_KIND to size variables for Hollerith
constants doesn't seem so useful. But in any case, if you don't
know the number of bits per character, it doesn't help much.

There is the additional problem that SELECTED_INT_KIND uses
decimal digits, which isn't so convenient when you want bits
or bytes.

> I think with gfortran you ask for integer*4, but I thought
> these weren't portable.

They aren't. I believe that the PDP-10 systems allowed
INTEGER*4 for a 36 bit integer holding five ASCII characters.

But if you want to do more than just read and write characters,
the best way is with one character per INTEGER variable, and A1
format. As all systems have to be able to hold at least one
character, that is portable, though a little less efficient.

-- glen
From: glen herrmannsfeldt on
Richard Maine <nospam(a)see.signature> wrote:
(snip)

> Not 100% guaranteed portable as of now, athough I think f2008 adopted a
> proposal of mine to make it simple and portable.

> For f90/f95/f2003, it will suffice in practice to do something like
> selected_int_kind(9). That's what I use. That doesn't strictly guarantee
> a 4-byte integer... but you won't find any compilers where that's not
> what you get.

Until a system comes along with the smallest integer of 64 bits.
There might have been a Cray system where C char was 64 bits.
Also, if anyone writes a F2003 compiler for a 36 bit machine,
then selected_int_kind(9) will likely give you 36 bits.

> A somewhat obscure way to sort of guarantee a 4-byte integer in f2003 is
> to use the C interop stuff (see C_INT32_T). But it seems a bit odd to go
> via C interop for such a thing if you aren't actually needing it for C
> interop. That does assume both that you have a compiler that supports
> the f2003 C interop stuff, and that the targetted companion C processor
> has int32_t. On the whole, I'd say you are beter off to just use the
> selected_int_kind(9) as it will work on more compilers (namely all of
> them that actually exist for f90 or later).

Well, one reason you might do it is to work with files that will
be read in by C programs that expect a specific size. In that
case, it would be indirectly C interoperability.

-- glen
From: Richard Maine on
glen herrmannsfeldt <gah(a)ugcs.caltech.edu> wrote:

> Since Fortran added CHARACTER in Fortran 77, and KIND not until
> later, using SELECTED_INT_KIND to size variables for Hollerith
> constants doesn't seem so useful. But in any case, if you don't
> know the number of bits per character, it doesn't help much.

Well, yes. I was ignoring the part about Hollerith. I had skimmed past
that quickly enough that it didn't stick in my mind. I focussed just on
the question about how to ask for a 4-byte integer. Had I taken another
second or so to process that this was being asked in relation to
Hollerith, I'd probably not have bothered to answer.

Using selected_int_kind for Hollerith is .... um... "pointless" seems
too mild a word. I'd think it closer to some kind of candidate for the
most inappropriate mixture of styles that one can devise. Expecting to
do so portably is beyond the pale.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: glen herrmannsfeldt on
Richard Maine <nospam(a)see.signature> wrote:
(snip)

> Using selected_int_kind for Hollerith is .... um... "pointless" seems
> too mild a word. I'd think it closer to some kind of candidate for the
> most inappropriate mixture of styles that one can devise. Expecting to
> do so portably is beyond the pale.

I would like to see a Fortran 2003 compiler on a 36 bit machine,
though. Not that I would use Hollerith constants on one.

-- glen