[英]What does o'377' mean in Fortran 77?
What does it mean o'377' in Fortran 77? Fortran 77 中的 o'377' 是什么意思? When I tried to print it outputs 255.
当我尝试打印它时输出 255。
print*,"result", o'377'
which returns返回
result 255
It's an octal (base 8) representation.这是一个八进制(基数为 8)的表示。 377 octal is 255 decimal or FF hex.
377 八进制是 255 十进制或 FF 十六进制。
This is what they call a boz-literal-constant :这就是他们所说的boz-literal-constant :
A binary, octal, or hexadecimal constant ( boz-literal-constant ) is a sequence of digits that represents an ordered sequence of bits.
二进制、八进制或十六进制常量 ( boz-literal-constant ) 是表示有序位序列的数字序列。 Such a constant has no type .
这样的常量没有类型。
R764 boz-literal-constant is binary-constant , octal-constant or hex-constant
R764 boz-literal-constant是binary-constant , octal-constant或hex-constant
R765 binary-constant isB ' digit [ digit ] ... '
orB " digit [ digit ] ... "
R765二进制常数是
B ' digit [ digit ] ... '
或B " digit [ digit ] ... "
C7107 (R765)digit
shall have one of the values0
or1
.C7107 (R765)
digit
应具有值0
或1
。
R766 octal-constant isO ' digit [ digit ] ... '
orO " digit [ digit ] ... "
R766八进制常数为
O ' digit [ digit ] ... '
或O " digit [ digit ] ... "
C7108 (R766) digit shall have one of the values0
through7
.C7108 (R766)数字应具有值
0
到7
。
R767 hex-constant isZ ' hex-digit [ hex-digit ] ... '
orZ " hex-digit [ hex-digit ] ... "
R767 hex-constant是
Z ' hex-digit [ hex-digit ] ... '
或Z " hex-digit [ hex-digit ] ... "
R768 hex-digit is digit orA
throughF
R768 十六进制数字是数字或
A
到F
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.
C7109 (R764) boz-literal-constant只能在 DATA 语句中作为data-stmt-constant出现,或者在 16.9 中明确允许作为内部过程的实际参数出现。
source: Fortran 2018 Standard Section 7.7
来源: Fortran 2018 标准第 7.7 节
As is seen from the Standard, a boz-literal constant has no type and can only appear in data-statements or some implicit functions.从标准中可以看出,boz-literal 常量没有类型,只能出现在数据语句或一些隐式函数中。 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.然而,在 Fortran 90 中,这也是无效的,因为人们只能在 DATA 语句中使用 boz-literal 常量。 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.注意:一些编译器允许在 DATA 语句之外使用 boz-literal-constants。 Solaris-studio converts them to the type required by the context.
Solaris-studio 将它们转换为上下文所需的类型。 Other compilers might have different opions on that.
其他编译器可能对此有不同的看法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.