Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran 忽略命名常量数组和字符串的大小和长度_Fortran - Fatal编程技术网

Fortran 忽略命名常量数组和字符串的大小和长度

Fortran 忽略命名常量数组和字符串的大小和长度,fortran,Fortran,在Fortran中,在声明命名常量数组时有没有办法省略大小?我只是觉得没有必要计算数组元素 我有如下想法 integer, parameter :: a(???) = [1, 2, 1, 2, 1, 4] 常量字符串呢 character(len=???), parameter :: a = "Hello world. This is a very long string." 我看到的一个明显的解决方案就是在这里使用一个非常大的数字(例如1024),并在我们想要访问它的时

在Fortran中,在声明命名常量数组时有没有办法省略大小?我只是觉得没有必要计算数组元素

我有如下想法

integer, parameter :: a(???) = [1, 2, 1, 2, 1, 4]
常量字符串呢

character(len=???), parameter :: a = "Hello world. This is a very long string."
我看到的一个明显的解决方案就是在这里使用一个非常大的数字(例如1024),并在我们想要访问它的时候调用
trim
。 这看起来并不像可能的那么好



注意:我认为在这里使用预处理器(定义预处理器宏并在其上调用
len
)不是一种优雅的方式。

可以对第一种情况使用隐含的形状数组,对字符大小写使用类似的语法

ijb@ijb-Latitude-5410:~/work/stack$ cat parm.f90
Program parm

  Implicit None ( External, Type )

  Integer, Dimension( 1:* ), Parameter :: a = [1, 2, 1, 2, 1, 4]

  Character(len=* ), Parameter :: b = "Hello world. This is a very long string."

  Write( *, * ) a, b
  
End Program parm
ijb@ijb-Latitude-5410:~/work/stack$ gfortran --version
GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ijb@ijb-Latitude-5410:~/work/stack$ gfortran -Wall -Wextra -fcheck=all -std=f2018 -g -O parm.f90 
ijb@ijb-Latitude-5410:~/work/stack$ ./a.out
           1           2           1           2           1           4 Hello world. This is a very long string.