program x
character(len=1024) :: foo
integer:: ret
foo = 'ls'
call system(foo, ret)
end program
此程序在ifort上与SIGSEGV崩溃。
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.
这是一个错误还是一个功能?
答案 0 :(得分:3)
如果我复制代码,我可以重现您所看到的错误(Linux,ifort 11.0 20090131)。但是,检查英特尔fortran编译器手册表明它是一个函数而不是子例程。如果我将代码修改为:
program x
character(len=1024) :: foo
integer :: ret
foo = 'ls'
ret = system(foo)
end program x
然后它成功运作。
答案 1 :(得分:2)
嗯,这适用于我的机器(ifort,xp sp3)
CHARACTER(LEN=1024) :: FOO
INTEGER :: RET
FOO = 'dir'
CALL SYSTEM(FOO, RET)
READ(*,*)
END
还有
RET = SYSTEM(FOO)
也适用于您正在使用的同一ifort,xp sp2。