我正在使用第三方项目add_subdirectory,另一个项目声明cmake_minimum_required(VERSION 2.8.11),并且使用最近的 CMake 我得到:
CMake Deprecation Warning at External/libmsym/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
Run Code Online (Sandbox Code Playgroud)
由于这是一个单独的项目(它作为 git 子模块获取)并且我没有写入权限,因此我无法真正按照建议解决问题。如果这是通过配置的ExternalProject,我可以使用该PATCH_COMMAND功能,但我认为在这种情况下我不能做类似的事情。除了为这个挑剔创建一个分支之外,还有其他方法可以禁用此警告或覆盖cmake_minimum_required子目录中的语句吗?
编辑:显然CMAKE_WARN_DEPRECATED或-Wno-deprecated可以做到这一点,但前者有一些奇怪的地方(它必须保存在缓存中才能工作,请参阅Cannot set CMAKE_WARN_DEPRECATED inside the CMakeLists.txt),这使得在本地切换特定的操作变得很麻烦add_subdirectory。
intent(in)我想知道通过与相应实际参数关联的指针修改虚拟参数是否合法/安全。特别是在子例程调用之前建立指针关联时。
例如,以下内容可以吗(它似乎与 gfortran 一起工作正常)?
program test
implicit none
type compound
integer, allocatable :: A1(:)
integer, pointer :: A2(:,:)
end type compound
type(compound), target :: my
integer :: n=5, i
allocate(my%A1(n**2))
my%A2(1:n,1:n) => my%A1(:)
do i=1,n**2
my%A1(i) = i
end do
do i=1,n
print *, my%A2(i,:)
end do
call assign_A(my)
do i=1,n
print *, my%A2(i,:)
end do
contains
subroutine assign_A(var)
type(compound), intent(in) :: var
var%A2(:,:) = 42
end subroutine
end program test
Run Code Online (Sandbox Code Playgroud)
诀窍是用户定义的类型包含一个指针和一个目标,前者指向后者。它的实例作为传递intent(in),并在子例程中通过指针组件对其进行修改(intent(in)可以修改指针指向的值)。我对它的工作原理感到有点惊讶,但也许这只是编译器缺少诊断。如果我直接改变var%A1那当然会失败。
编辑:上述程序的输出(用 …
我可以编写此代码以与 python 2.x 和 3.x 一起使用,而无需对它们进行显式测试吗?
\n\n# -*- coding: utf-8 -*-\nfrom __future__ import (unicode_literals, division, absolute_import, print_function)\n\nimport os\nimport sys\n\nif (sys.version_info[0] > 2):\n # python 3.x\n os.environ['foo'] = 'b\xc3\xa1r'\n print(os.environ['foo'])\nelse:\n # python 2.x\n os.environ['foo'] = 'b\xc3\xa1r'.encode('utf8')\n print(os.environ['foo'].decode('utf8'))\nRun Code Online (Sandbox Code Playgroud)\n 假设我有类似的东西:
real, dimension(:), allocatable :: S
integer, dimension(:) :: idx
...
S = S(idx)
Run Code Online (Sandbox Code Playgroud)
whereS和idx在分配之前正确分配/初始化。
Fortran 标准对 的内存位置(地址)有S什么说法(如果有的话)?分配后它应该留在同一个地方吗?是否未指定(由编译器决定)?是否有所作为,如果S不是allocatable?
完整示例:
$ cat test.f90
program test
implicit none
real, dimension(:), allocatable :: S
integer :: i, idx(7) = [1,3,5,7,2,4,6]
allocate(S(size(idx)))
do i=1,size(S)
S(i) = i*i
end do
write(6,*) S
write(6,*) loc(S)
S = S(idx)
write(6,*) S
write(6,*) loc(S)
S(:) = S(idx)
write(6,*) S
write(6,*) loc(S)
deallocate(S)
end program
$ sunf90 -V
f90: …Run Code Online (Sandbox Code Playgroud)