Error Return Type Mismatch Of Function
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with error return type mismatch of function at (1) (real(4)/real(8)) us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow return type mismatch of function fortran Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up
Vbscript Function Return Array Type Mismatch
gfortran 4.8.0 bug? Return type mismatch of function up vote 1 down vote favorite 1 I just use gfortran 4.1.2 and gfortran 4.8.0 to compile the following simple code: function foo(a, b) result(res) integer, intent(in) :: a, b integer res res =
Function Has No Implicit Type
a+b end function foo program test integer a, b, c c = foo(a, b) end program test gfortran 4.1.2 succeeds, but gfortran 4.8.0 gives the weird error: test.F90:14.11: c = foo(a, b) 1 Error: Return type mismatch of function 'foo' at (1) (REAL(4)/INTEGER(4)) Any idea? gfortran share|improve this question asked May 9 '13 at 5:39 Li Dong 4921823 See stackoverflow.com/questions/16446397/… –High Performance Mark May 9 '13 at 5:48 Thanks @Mark! I am writing a tool for scanning Fortran codes and type mismatch in argument fortran building them, this is just a test. And I am more familiar with module. Personally, I add implicit none in every code of my Fortran project, but forget to add it in the test! And I also need to declare function foo in the program. –Li Dong May 9 '13 at 6:05 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted There is a bug in your code, namely that you don't specify the return type of the function foo in the main program. Per the Fortran implicit typing rules it thus gets a type of default real. You should (1) always use 'implicit none', furthermore if at all possible, (2) use modules or contained procedures thus giving you explicit interfaces. The reason why GFortran 4.1 doesn't report this error is that older versions of GFortran always functioned in a 'procedure at a time' mode; thus the compiler is happily oblivious to any other functions in the same file. Newer versions work in 'whole file' mode (default since 4.6) where the compiler 'sees' all the procedures in a file at a time. This allows the compiler to catch errors such as the one in your code, and also provides some optimization opportunities. share|improve this answer answered May 9 '13 at 6:05 janneb 23.1k24769 Yes, you got it! See my comment above. Thanks for clarify the rule of Fortran! –Li Dong May 9 '13 at 6:07 add a comment| Your Answer draft save
LearningModern CodeNetworkingOpen SourceStorageToolsDeveloper TypeEmbedded SystemsGame DevMediaTechnical, Enterprise, HPCWebOSAll ToolsAndroid*HTML5Linux*OS X*Windows*ResourcesCode SamplesContact SupportDocumentationFree SoftwareIntel Registration CenterProduct ForumsSDKsResourcesPartner with IntelAcademic ProgramPartner SpotlightBlack Belt DeveloperDeveloper MeshInnovator ProgramSuccess StoriesLearnBlogBusiness TipsEventsVideosSupportContact SupportDeveloper EvangelistsFAQsForums Search
Type Mismatch In Argument Passed Real(4) To Real(8)
form Search You are hereHome › Forums › IntelĀ® Software implicit none fortran Development Products › IntelĀ® Fortran Compiler for Linux* and Mac OS X* FacebookLinkedInTwitterDiggDeliciousGoogle Plus Type fortran type casting mismatch error when calling function Type mismatch error when calling function littleprince Fri, 06/03/2011 - 23:06 When I run this simple program, I get an http://stackoverflow.com/questions/16455130/gfortran-4-8-0-bug-return-type-mismatch-of-function error: function getlength has no implicit type, type mismatch (unknown/integer). (I understand that there is no real need for the function at all, I could just use len() in the main. This program is for test purposes only.) What am I doing wrong/how can I fix it? Thanks in advance https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/270818 for your help! program test implicit none character(len = 100) :: input integer :: length = 0 read *, input length = getLength(input) print *, length end integer function getLength(array) character(len = 100) array getLength = len(array) end RSS Top 4 posts / 0 new Last post For more complete information about compiler optimizations, see our Optimization Notice. mecej4 Sat, 06/04/2011 - 03:19 You have to declare getLength as type INTEGER in the main program. Without such a declaration, the implicit typing rules make it REAL, which clashes with the later declaration of the function as INTEGER. There is a bigger problem with your code. The function will return 100 instead of what you may have expected. You need to read books/manuals to see how character strings are handled in Fortran. This problem will not go away even if you replace the reference to getLength by one t
[ date ] [ thread ] [ subject ] [ author ] On 10-04-2011, at 10:42, Christophe Dutang wrote: > Dear all, > > I use R https://stat.ethz.ch/pipermail/r-sig-mac/2011-April/008160.html 2.12.2 to build, install and check my packages, in particular randtoolbox. On my http://archive.ambermd.org/201111/0443.html macbook with OS X 10.6.7, the gcc installed is > i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) . From http://r.research.att.com/tools/, I have also downloaded gfortran (GNU Fortran (GCC) 4.2.3). > > With this framework, I do not get any error and warnings on the randtoolbox package. > Looking at your Fortran type mismatch code, I think you have just been lucky. > But using gcc 4.6 on linux, Kurt Hornik get the following errors in the only one Fortran file of the package: > > LowDiscrepancy.f:180.26: > > QN(I, J) = HQNORM(QUASI(J)) > 1 > Error: Return type mismatch of function 'hqnorm' at (1) (REAL(4)/REAL(8)) HQNORM is not declared with a type in the routine you are using return type mismatch it. Implicit declaration most likely implies it is real (real*4). But later on it is typed as double precision. Asking for trouble. > LowDiscrepancy.f:1393.29: > > TEMP1 = TEMP1 + TEMP01 > 1 > Warning: Possible change of value in conversion from REAL(4) to INTEGER(4) at (1) Temp01 is not declared and thus implicitly real*4 (most likely). > LowDiscrepancy.f:405.29: > > QN(I, J) = SQNORM(QUASI(J)) > 1 > Error: Return type mismatch of function 'sqnorm' at (1) (REAL(4)/REAL(8)) > make: *** [LowDiscrepancy.o] Error 1 > see remark above about hqnorm. Same problem. > > My first question is which is the standard version of gcc to use? from http://cran.r-project.org/web/checks/check_flavors.html#r-release-macosx-ix86, it should gcc 4.2.1 ? If I have to update gcc, where can I find the binaries? > gcc-4.2.1 comes with Xcode. And gfortran must be obtained from http://r.research.att.com/tools/ and should match the Xcode version. That's all. But looking at that page I don't see a gfortran available for Apple gcc 5666 (from Xcode 3.2.6?). I am using gfortran 5664 with Xcode 3.2.5. Simon knows more about this. > My second question, in the case I can reproduce this error on my macbook or a linux,
to ] Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ] From: Jose Borreguero