开发者

Crash of simple fortran program using system()

program x
   character(len=1024) :: foo 
   integer:: ret 

   foo = 'ls'
   call system(foo, ret)
end program

This program crashes with SIGSEGV on ifort.

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
a.out              0000000100000F0B  Unknown               Unknown  Unknown
a.out              0000000100000EAA  Unknown               Unknown  Unknown
a.out              0000000100000E8B  Unknown               Unknown  Unknown
a.out     开发者_如何转开发         0000000100000E0C  Unknown               Unknown  Unknown
a.out              0000000100000DA4  Unknown               Unknown  Unknown

gdb:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x0000000100000f0a in allocCstr ()
(gdb) bt
#0  0x0000000100000f0a in allocCstr ()
#1  0x0000000100000eaa in system_ ()
#2  0x0000000100000e0c in main ()

ifort --version

ifort (IFORT) 11.1 20100806
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

Is this a bug or a feature?


I can reproduce the error that you're seeing if I copy your code (Linux, ifort 11.0 20090131). However, a check of the Intel fortran compiler manual suggests that it's a function rather than a subroutine. If I modify the code to:

program x
    character(len=1024) :: foo
    integer             :: ret

    foo = 'ls'
    ret = system(foo)
end program x

Then it works successfully.


Well, this works on my machine (ifort, xp sp3)

  CHARACTER(LEN=1024) :: FOO
  INTEGER :: RET

  FOO = 'dir'
  CALL SYSTEM(FOO, RET)
  READ(*,*)

  END

Also with

  RET = SYSTEM(FOO)

Also works on the same ifort you're using, xp sp2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜