- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 !
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You probably need to say:
real(prec) function func(x)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried
real(prec) function func(x)
It works! Thanks a million Steve !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quite right - it can make the code clearer. I was trying to say that using RESULT in this case was not a correctness issue.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page