- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following code compiles without any warning when I use Intel Fortran whereas I get a warning when using gfortran -- "Extension: Unary operator following arithmetic operator (use parentheses)". I've been looking through e.g. https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2024-0/summary-of-language-extensions.html and can't find where this behavior is documented. Can someone please point me to the right location?
program invalid_sequence_of_operators
implicit none
real :: a, b
b = 1
a = b + -5 * b
write(*,*)a
end program invalid_sequence_of_operators
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is an old DEC/Intel extension. The extension is documented, but the relevant lines are not easy to find (unless you know at least a part of the exact wording!). In the manual page that you showed a link for, just before "Examples", you can read this:
Normally, two operators cannot appear together. However, Intel® Fortran allows two consecutive operators if the second operator is a plus or minus.
The manual does not state how such a non-standard expression will be evaluated, but my recollection is that a minus or a plus preceding a constant or a variable name, if it is the second of two consecutive operators, has higher precedence than the first of the two consecutive operators.
You can use compiler options to flag such extensions as errors.
S:\LANG>ifort /warn:stderrors /stand=f03 expext.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.11.0 Build 20231010_000000
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.
expext.f90(5): error #8810: Consecutive operators are an extension to the Fortran 2003 standard.
a = b + -5 * b
--------^
compilation aborted for expext.f90 (code 1)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is an old DEC/Intel extension. The extension is documented, but the relevant lines are not easy to find (unless you know at least a part of the exact wording!). In the manual page that you showed a link for, just before "Examples", you can read this:
Normally, two operators cannot appear together. However, Intel® Fortran allows two consecutive operators if the second operator is a plus or minus.
The manual does not state how such a non-standard expression will be evaluated, but my recollection is that a minus or a plus preceding a constant or a variable name, if it is the second of two consecutive operators, has higher precedence than the first of the two consecutive operators.
You can use compiler options to flag such extensions as errors.
S:\LANG>ifort /warn:stderrors /stand=f03 expext.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.11.0 Build 20231010_000000
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.
expext.f90(5): error #8810: Consecutive operators are an extension to the Fortran 2003 standard.
a = b + -5 * b
--------^
compilation aborted for expext.f90 (code 1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey, thanks! That's exactly what I was looking for. I'm using a code linter (Coverity cov-run-fortran) that has an option to recognize Intel Fortran extensions. The linter doesn't recognize this one so having the Intel documentation reference is very helpful when pointing out that the linter is not working correctly. Agreed that it's hard to find, although this gives me a bit better feel for how the docs are laid out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I discuss this, and other related issues, in Doctor Fortran in "Order! Order!" - Doctor Fortran (stevelionel.com)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks @Steve_Lionel -- that's an interesting one!
![](/skins/images/872293744008A34B36F8ABF94A46CC66/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