Richard Maine <nos...@see.signature> wrote:
> Clive Page <
use...@page2.eu> wrote:
(snip, I wrote)
>> >> the default INTEGER, REAL, and LOGICAL to have the same
>> >> size, relying on it might cause problems.
>> > And the reason for this is presumably so that one CAN rely on it,
>> > assuming standard-conforming code and "processor".
> Yes. I found Glen's statement a bit confusing. I would say that you CAN
> rely on any implementation you are likely to run into following the
> standard in this regard. I recall some quite old f77 (or maybe even f66)
> implementations that failed to follow the standard, at least by default.
> The one I recall did have an option to follow the standard even though
> that wasn't the default. But that doesn't count as a compiler that you
> are likely to run into unless hearing some of us oldsters talk about it
> on this forum counts as running into it.
Yes, many 16 bit systems used 16 bit INTEGER and 32 bit REAL,
without wasting 16 more bits on the INTEGER. (Then again, the 704
and successor 36 bit systems stored 16 bit signed integers in 36
bit words.)
But the reason for the statement was padding. In the Fortran 66,
and I believe Fortran 77 days, (at least for the implementations
that I knew about) padding wasn't allowed for COMMON. Mixing
DOUBLE PRECISION into a COMMON block, it wasn't hard to generate
alignment errors. Some systems would do a run-time fixup by
copying the data somewhere else, doing the operation, then copying
back.
> However, you do have to be careful about where the standard's
> requirement on this applies. It mostly applies "in a storage association
> context." That's almost redundant in that almost anywhere that you can
> directly see the effects of storage size turns out to be a storage
> association context - either that or in code that is clearly nonstandard
> for other reasons as well.
> Looks like I/O is one area where the size can matter even though it does
> not count as a storage association context. I hadn't thought of it like
> that before now, but it seems to be so.
I wasn't sure either way when I wrote that one. The systems that
I know about don't have alignment requirements for I/O, but I wouldn't
be sure that none did.
>> It's not clear to me whether the identical size requirement applies to
>> an I/O list - essentially that is why the INQUIRE by I/O list exists, so
>> one can find the effective length of the items of a given list, as far
>> as the current compiler is concerned. How it aligns the items, e.g.
>> whether each DOUBLE PRECISION real is aligned on an 8-byte boundary in
>> memory, is something that the programmer doesn't have to worry about any
>> more.
> Inquire by I/O list is also needed because of different processors using
> different units of measure for the file storage unit. In fact, that's
> much more the reason I've used it.
Yes. But even if you determine that INTEGER is four times the
size of CHARACTER*1, it might not be good to rely on that when
doing I/O. If you INQUIRE a whole I/O list, the system will include
any padding.
> I was thinking that the standard did require data to be stored in an
> unformatted file without padding, but on reading the relevant bits, I
> don't see such a requirement. To the contrary, I see implications that
> padding might be allowed in some cases, as you say. Good thing I didn't
> post based on my guess without checking.
Possibly along with the removal of the restriction on COMMON.
> For unformatted stream, the standard (f2003, as that's when stream was
> introduced) is pretty explicit on the subject of padding. One might
> guess that this would extrapolate to unformatted record-oriented, but I
> don't see that the standard requires that particular consistency. From
> 9.2.4 of f2003
In C, it isn't unusual to put data into a struct, and then use that
for the I/O, maybe even when there is no other need for the struct.
Pl/I RECORD I/O (the equivalent of UNFORMATTED) allows for only
one data item, usually a structure, per I/O operation.
(I will guess that was inherited from COBOL.)
In the C struct case, and the PL/I structure case, any data
padding will go into the I/O operation.
> "For a file connected for unformatted stream access, the processor
> shall not have alignment restrictions that prevent a value of any
> type from being stored at any positive integer file position."
But it can restrict for file position zero?
> Note 9.12 elaborates a bit on the implications of that requirement.
-- glen