Re: writing characters using Z edit descriptors
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Sat, 30 Jul 2005 12:05:56 -0700
robert.corbett@xxxxxxx wrote:
Many, perhaps most, Fortran implementations allow characters to be written using Z edit descriptors. A member of Sun's Fortran team recently pointed out that different implementations work differently on little endian machines. Consider the program
PROGRAM MAIN
INTEGER I
DATA I/4HABCD/
CHARACTER*4 S/'ABCD'/
PRINT '(A4)', I
PRINT '(Z8)', I
PRINT '(A4)', S
PRINT '(Z8)', S
END
Using some compilers, the output is
ABCD 44434241 ABCD 41424344
Using other compilers, the output is
ABCD 44434241 ABCD 44434241
In the first case, the string is treated as if it is an array of 4 one-byte integers. In the second case, the string is treated as if it is a single 4-byte integer.
And I suppose the standard doesn't say anything about this. The VMS DUMP command, which prints a hex and ASCII dump of a file, prints the ASCII values left to right, and hex values right to left so that the hex values agree with normal mathematical notation.
Initializing floating point variables with Z constants on VAX requires unusual ordering such that the sign bit is near the middle.
The program is nonstandard, so the Fortran standard does not say what the program should do. Which way of writing strings under a Z edit descriptor do you prefer?
As long as you can't EQUIVALENCE between character and other types, it doesn't seem that there is a requirement to treat a character variable as a 4-byte integer. Consider, though, printing a four character string with Z4 format? or Z10 format? or even Z5 format? Treating it as a four byte integer would seem to give strange results in those cases.
Note that this problem does not arise on big endian machines.
Another reason why big endian makes more sense for any processor more complex than the 6502.
-- glen
.
- Follow-Ups:
- Re: writing characters using Z edit descriptors
- From: Phillip Helbig---remove CLOTHES to reply
- Re: writing characters using Z edit descriptors
- References:
- writing characters using Z edit descriptors
- From: robert . corbett
- writing characters using Z edit descriptors
- Prev by Date: Re: fftw3 accepts extra options during compile time
- Next by Date: Re: number of columns
- Previous by thread: Re: writing characters using Z edit descriptors
- Next by thread: Re: writing characters using Z edit descriptors
- Index(es):
Relevant Pages
|
Loading