This happens because you are using default formatting for the output.
print*
is equivalent to write(unit=*,fmt=*)
, where fmt=*
means use default formatting for the output, which may be compiler dependent. Default formatting uses as much space is possibly needed by the data type being output, without making adjustments based on the value.
Consider following code:
integer(kind=4) :: a ! short integer for my compiler
integer(kind=8) :: b ! long integer for my compiler
a = 23
b = huge(a)
print*,a ! small value, short integer, we expect spaces
print*,huge(a) ! maximum value, short integer, we expect no spaces
print*,huge(b) ! maximum value, long integer, we expect no spaces
print*,b ! medium lenght value, long integer, we expect spaces
end
When compiler with gfortran, the output is:
23
2147483647
9223372036854775807
2147483647
The first line is a small number in 4-byte integer representation. Notice the spaces to fill up to the maximum possible size. Second line is the largest value a 4-byte integer can take. Fits tightly in output, no spaces. Third line is the largest value of an 8-byte integer. Fits tightly. The fourth line is the same value from the 2nd line, but in 8-byte integer representation. Notice the spaces.
This answers why you get spaces in output for default formatting. It does not quite answer your question exactly, which is why there are no spaces in output for a quad-precision integer. I don't know. Neither of my compilers (pgf90 10.6-0
, ifort 12.0.2.137
, gfortran 4.5.1
) support quad-precision integer. Could be a compiler hackery. Someone might have more experience with this part, and hopefully they will chime in.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…