Re: writing characters using Z edit descriptors



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

.



Relevant Pages

  • Re: Vb 2003 Framework 1.1
    ... >> Ok taking this code below when i look at my LoByte and HiByte ... > If 3595 was a hex number, then the high byte would be hex 35 which ... so i would need to convert the 3595 into this type of format: ... Do you want to convert to a string? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Vb 2003 Framework 1.1
    ... i should get a Lobyte as 149 and a hibyte as 53 ... 10 and the low byte is hex B which is 11 base 10. ... so i would need to convert the 3595 into this type of format: ... Do you want to convert to a string? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to split Hex String and fill byte buffer in VB 6.0
    ... I am receiiving a string from serial port which is also in hex format. ... Please tell me howw to do that. ...
    (microsoft.public.vb.general.discussion)
  • Re: Convert Hex to Decimal in arraylist
    ... Hexadecimal format. ... You can convert anIntegervalue into a string in different formats, ... You can convert a string, containing a number in hex format, into anIntegervalue by using "Convert.ToInt32" ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Parsing blanks in Fortran 90/95
    ... your read statement (using A edit descriptors). ... If your particular compiler happens to do that (and maybe it ... the string is the numeric field. ...
    (comp.lang.fortran)

Loading