简体   繁体   English

o'377' 在 Fortran 77 中是什么意思?

[英]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-constantbinary-constantoctal-constanthex-constant
R765 binary-constant is B ' digit [ digit ] ... ' or B " digit [ digit ] ... " R765二进制常数B ' digit [ digit ] ... 'B " digit [ digit ] ... "
C7107 (R765) digit shall have one of the values 0 or 1 . C7107 (R765) digit应具有值01
R766 octal-constant is O ' digit [ digit ] ... ' or O " digit [ digit ] ... " R766八进制常数O ' digit [ digit ] ... 'O " digit [ digit ] ... "
C7108 (R766) digit shall have one of the values 0 through 7 . C7108 (R766)数字应具有值07
R767 hex-constant is Z ' hex-digit [ hex-digit ] ... ' or Z " hex-digit [ hex-digit ] ... " R767 hex-constantZ ' hex-digit [ hex-digit ] ... 'Z " hex-digit [ hex-digit ] ... "
R768 hex-digit is digit or A through F R768 十六进制数字是数字AF

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM