- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a call where a Logical*2 argument is passed to a subroutine expecting an (in/out) Logical*4 - a recipe for trouble as you might imagine, but the compiler doesn't whinge? Is there a compiler option that will flag this?
Edit:
Actually, this seems to be occuring and causing problems in several places...
IVF 12.1.3534.2010, on Win7 x64
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use the /warn:all option, and it will warn you about mismatched argument types:
warning #6075: The data type of the actual argument does not match the definition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Generated interface checking, on by default in a Debug configuration, will detect this. From the command line it's /warn:interface (or /warn:all).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks - these warning have brought up another question though - why is an (Int2 - 1) not an Int2? I know integers have a default kind but surely it is safer in this instance to assume the smallest kind is meant?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, when differing data types are combined, it's done in the type with bigger range. As far as int(2) is concerned, there hasn't been a Fortran platform which could do it more efficiently in 16 bits (aside from memory usage) for over 2 decades.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
*deleted duplicate post*
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re-reading my comment I guess I wasn't clear. Suppose you have:
Subroutine MySub(I2)
which you then call with:
Call MySub(I2 -1)
If your default integer kind is I4, you need to call that like this to avoid the warning:
Call MySub(Int2(I2 - 1))
Surely the compiler could figure that out?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Explicit interface would be preferable if you are going to pass an expression where integer(2) is expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Explicit interface would be preferable if you are going to pass an expression where integer(2) is expected.
Yeah, old code is old but, (unfortunately sometimes!) old code still works...mostly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
why is an (Int2 - 1) not an Int2? I know integers have a default kind but surely it is safer in this instance to assume the smallest kind is meant?...Call MySub(Int2(I2 - 1))
Surely the compiler could figure that out?
The constant 1 (or -1) is a default integer constant. Default integers are not 16-bit integers in any current compiler. Most probably, the integer constant is a signed 32-bit integer.
For a compiler to read an individual programmer's mind is not safe, nor are compilers smart enough to do so. There is a reason why we have the Fortran Standard, and compilers are expected to conform to the standard.
In Fortran, an expression has a type, and there are rules for treating mixed-type expressions. Try this short program to understand the conflicts and concepts involved. Try to guess the answer before you run the program and see the output.
[fortran]program mismatch
implicit none
integer*2 :: i2
integer, parameter :: b2=kind(i2)
write(*,*)kind(i2+131),kind(i2+131_b2)
end program mismatch[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not to discredit or contradict previous posts, I face exactly this situation quite frequently, and here is my explanation:
The argument has two parts, variable i2 and constant 1. The variable is integer(2) and the constant is integer(4). When the compiler forms the sum i2-1, the i2 is promoted to integer(4) to match the constant, with the result (i2 - 1) is integer(4).
I usually fix this by specifying (i2 - 1_2), where ?_2 is a shorthand way of writing int2(?).
Don't know if this is highly recommended by Intel but it is easiest for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
![](/skins/images/7B0AB6865064EAE32B30EC9A4E94B48A/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page