[FORTRAN] Using builtin-function

Hi everyone.

I wrote following code which call buildin function signal. And I compiled this code by following command. But I failed compilation. Should I pass the any linker option to compiler ? Compiler version is 13.5. Please teach me.

Source (test.F)

       program test
       implicit none
       real a,b,c
       integer ret, sigNum, flg
       external divByZeroHdler
       flg = -1
       !! P;ease reference /usr/include/bits/signum.h
       sigNum = 8 
       a = 3
       b = 0
       WRITE(*,*) 'Hello'
       ret = signal(sigNum, divByZeroHdler, flg)
       c = a/b;
       WRITE(*,*) 'Good bye'

       end program test

       subroutine divByZeroHdler()
         WRITE(*,*) 'divByZeroHdler is called'
       end subroutine divByZeroHdler

compile command

$ pgfortran --version

pgfortran 13.5-0 64-bit target on x86-64 Linux -tp sandybridge 
Copyright 1989-2000, The Portland Group, Inc.  All Rights Reserved.
Copyright 2000-2013, STMicroelectronics, Inc.  All Rights Reserved.
$ pgfortran test.F 
PGF90-S-0038-Symbol, signal, has not been explicitly declared (test.F)
  0 inform,   0 warnings,   1 severes, 0 fatal for test

[/code]

Hi,

Eliminating the ‘implicit none’ statement should allow your program to compile with PGI Fortran. However, the code may generate a floating-point NaN value assigned to the variable c instead of raising SIGFPE, so you may not get the behavior you were expecting.

Hope this helps,

+chris

Is there any solution except eliminating ‘implicit none’ ?

Hi,

I think you need to declare your function. Adding

integer signal

or changing

integer ret, sigNum, flg

to

integer ret, sigNum, flg, signal

should work.

Cheers,
Kyle

Thanks, Kyle. That’s probably an even better solution than the one I suggested.

Best regards,

+chris