Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Please help this issue_ error #7977: The type of the function reference does not match

Arm_N_
Beginner
1,714 Views

Hi,

I ran some code on intel visual fortran compiler

(Intel(R) Visual Fortran Compiler Integration for Microsoft Visual Studio* 2008, 11.1.3471.2008, Copyright (C) 2002-2010 Intel Corporation Microsoft Visual Studio 2008 Version 9.0.21022.8.RTM On the help page it said "Intel® Visual Fortran Compiler Professional Edition 11.1")

I got this error and warning.

error #7977: The type of the function reference does not match the type of the function definition
warning #6371: A jump into a block from outside the block may have occurred.   [30]

When I checked the error, it involve the line that looked like

y=func(x)

where y, and x are real numbers and func is EXTERNAL function used in other subroutine. The function is defined like this.

real function func(x)

use para
implicit none

real(prec),intent(in)::x

When is is declared EXTERNAL elsewhere, it is like this:

real(prec),external:: func
integer,parameter :: prec=selected_real_kind(15,307)

This code I ran is said to be able to be compiled in ABSOFT PRO-FORTRAN 9.0 compiler with the following compilation options:
Target Type: Console Application
Warning Level: Level 3
Error Handling: Stop after 100
Max Internal Handle: 100000
Temporary String Size: 1024
Cache Optimizations: CACHE
Stack Size (Reserve): 0x10000000
Stack Size (Commit): 0x8000
Heap Size (Reserve): 0x100000
Heap Size (Commit): 0x1000

I am not sure what I need to change in my compiler so that it would be able to run this code properly.

Thank you very much !

 

 

0 Kudos
13 Replies
Steven_L_Intel1
Employee
1,714 Views

You have errors in your source code that were not detected by the other compiler.

The first error is saying that you have a mismatch between how you have declared a function in the caller and how the actual function is declared. An example:

program test
real f
print *, f(3)
end
double precision function f (i)
integer i
f = i
end

The second error is when you do something like this:

program test
goto 30
if (.true.) then
30 print *, "Hi"
end if
end

It's not legal to jump to a label inside a block construct. Probably in your case the GOTO is later in the code than the block construct.

0 Kudos
mecej4
Honored Contributor III
1,714 Views

You left out some important information. What is the type of func? Is it REAL(4) or REAL(8)? The error message indicates that the compiler had seen and remembered a type for func that is different from the type in the current compilation unit.

0 Kudos
Arm_N_
Beginner
1,714 Views

Sorry for leaving some information.  

The function is defined like this.

real function func(x)

use para
implicit none

real(prec),intent(in)::x

When it is declared EXTERNAL elsewhere, it is like this:

real(prec),external:: func
integer,parameter :: prec=selected_real_kind(15,307)

Could you please suggest which specific things I should change in this code?  Thanks !

0 Kudos
Steven_L_Intel1
Employee
1,714 Views

You probably need to say:

real(prec) function func(x)

0 Kudos
Arm_N_
Beginner
1,714 Views

I tried 

real(prec) function func(x)

It works! Thanks a million Steve !

 

 

0 Kudos
FortranFan
Honored Contributor III
1,714 Views

You may also want to consider using the RESULT attribute:

   function foo(x) result(retval)

      !.. Argument list
      real(prec), intent(in) :: x

      !.. Function result
      real(prec) :: retval

      retval = ..  

      return

   end function foo

 

0 Kudos
Arm_N_
Beginner
1,714 Views

Thanks, FortranFan, for further suggestion.  I will try.

0 Kudos
Steven_L_Intel1
Employee
1,714 Views

That's just a stylistic suggestion. Most people don't use RESULT unless the function is being called recursively, but it's not a bad habit to get into.

0 Kudos
Arm_N_
Beginner
1,714 Views

Hi,

I still have some unresolved problems. As Steve Lionel (Intel) suggested me, I could get rid off the error message and the code was able to compile, but the warning messages are still there.  There is no 'GOTO' statement to jump into any block.

I ran the code, and found the runtime error.  It said something like the subscript#2 of array 'NAMEARRAY' has value of 100 which exceed the upperbound value of 50... something like this

I wonder how this happened, since it can run using another abovementioned compiler.

Could anyone please suggest me what I should look for?

Thank you guys very much!

 

0 Kudos
Steven_L_Intel1
Employee
1,714 Views

Again, Intel Fortran has revealed an error in your code not caught by the other compiler. Your code is accessing an array outside its declared bounds. While the program may seem to run using the other compiler, the results are almost certainly incorrect.

We can't tell you how to fix the code without seeing the whole program and understanding what it is trying to do. So that will be your task.

0 Kudos
Arm_N_
Beginner
1,714 Views

Thanks for the suggestion.  I thought there might be some issue about the compiler.  I guess it is up to my work now, but thanks again !

0 Kudos
FortranFan
Honored Contributor III
1,714 Views

Steve Lionel (Intel) wrote:

That's just a stylistic suggestion. ..

Uh oh.. I only had substance in mind when I made the comment :-))   I only suggested RESULT keyword because I've noticed it help a couple of colleagues get over the pattern of running into problems with type incompatibility of function return values.  I figure since it involves declaring the result just like any other variable, it brings a little more focus on its type which might help coders get it right.

0 Kudos
Steven_L_Intel1
Employee
1,714 Views

Quite right - it can make the code clearer. I was trying to say that using RESULT in this case was not a correctness issue.

0 Kudos
Reply