Re: Reading GIF
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Tue, 21 Apr 2009 14:34:41 -0700
e p chandler <epc8@xxxxxxxx> wrote:
Reading a file of bytes as a stream of characters in Fortran is a work-
around that lets the programmer deal with a data type that Fortran
does not have - unsigned 1 byte integers.
It is a workaround that I have seen before, but recommend against.
Character type is *NOT* guaranteed to work for the purpose. It often
does, but the standard does not at all guarantee it. The standard *DOES*
allow the compiler to do "funny" things with bit combinations that do
not correspond to printable characters, and those "funny" things are not
necessarily restricted to printing. I have seen compilers that did some
such "funny" things.
In my opinion, if one needs a hack to model unsigned 8-bit integers, it
is a much "safer" bet to base the hack on storing the data as 8-bit
signed integers than as characters. In theory, a compiler might not
support 8-bit signed integers either, but then most do.
Yes, I know the caveats about doing this with 8-bit signed integers. But
it seems to me that every one of those caveats applies even more so to
hacking it with characters.
In my own code for such things (which I do happen to need a lot), I
consider it the kind of system-dependent thing that merits isolation. I
have a separate module to define the kinds of things I need to do with
8-bit data. I "normally" have the module use an 8-bit signed integer
data type for its underlying storage, but I have it isolated enough that
I could change to use a character type if needed for a particular
As it turns out, there was only one compiler that I tried to port to
that didn't have a suitable 8-bit signed integer... and it turned out to
have a (likely related) problem that kept characters from working out
either. The minimum size for a derived type was 2 bytes. I think a later
version of the compiler fixed the lack of an 8-bit integer kind at the
same time as it fixed the 2-byte minimum size for a derived type.
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
- Prev by Date: Re: Program Fails When Parameter Fixed Constants are Changed (F77) ??
- Next by Date: Re: Fortran member functions?
- Previous by thread: Re: Reading GIF
- Next by thread: Re: Reading GIF