小编Ø. *_*sen的帖子

这种字符串指针的使用安全吗?

在实现字符串实用程序功能时,我遇到了一些我认为可能不安全的字符指针表达式.我用谷歌搜索,搜索了SO,阅读了我的Fortran 95语言指南(Gehrke 1996)以及Google书籍中展示的各种摘录.但是,我找不到任何讨论这种特殊用法的消息来源.

ifort和gfortran都在没有警告的情况下编译以下程序:

PROGRAM test_pointer
  IMPLICIT NONE
  CHARACTER(LEN=100), TARGET :: string = "A string variable"
  CHARACTER(LEN=0), TARGET :: empty = ""
  CHARACTER(LEN=:), POINTER :: ptr

  ptr => NULL()
  IF(ptr == "") PRINT *, 'Nullified pointer is equal to ""'

  ptr => string(-2:-3)
  IF(ptr == "") PRINT *, 'ptr equals "", but the (empty) sub string was out of bounds.'

  ptr => empty(1:0)
  IF(ptr == "") PRINT *, 'ptr equals "", it was not possible to specify subarray within bonds' …
Run Code Online (Sandbox Code Playgroud)

standards fortran pointers

4
推荐指数
1
解决办法
531
查看次数

标签 统计

fortran ×1

pointers ×1

standards ×1