What does it mean o'377' in Fortran 77? When I tried to print it outputs 255.
print*,"result", o'377'
which returns
result 255
It's an octal (base 8) representation. 377 octal is 255 decimal or FF hex.
This is what they call a boz-literal-constant :
A binary, octal, or hexadecimal constant ( boz-literal-constant ) is a sequence of digits that represents an ordered sequence of bits. Such a constant has no type .
R764 boz-literal-constant is binary-constant , octal-constant or hex-constant
R765 binary-constant isB ' digit [ digit ] ... '
orB " digit [ digit ] ... "
C7107 (R765)digit
shall have one of the values0
or1
.
R766 octal-constant isO ' digit [ digit ] ... '
orO " digit [ digit ] ... "
C7108 (R766) digit shall have one of the values0
through7
.
R767 hex-constant isZ ' hex-digit [ hex-digit ] ... '
orZ " hex-digit [ hex-digit ] ... "
R768 hex-digit is digit orA
throughF
C7109 (R764) A boz-literal-constant shall appear only as a data-stmt-constant in a DATA statement, or where explicitly allowed in 16.9 as an actual argument of an intrinsic procedure.
As is seen from the Standard, a boz-literal constant has no type and can only appear in data-statements or some implicit functions. This implies that the notation:
print*,"result", o'377'
is invalid code since the octal representation has no type. The correct code would have read:
print *, "result", INT(o'377')
However, in Fortran 90 this would also have been invalid as one could only use boz-literal constants in DATA-statements. The only valid way would have been:
INTEGER :: constant
DATA constant /o'377'/
print *, "result", constant
note: Some compilers allow the usage of boz-literal-constants outside of the DATA statement. Solaris-studio converts them to the type required by the context. Other compilers might have different opions on that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.