- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Both http://fortranwiki.org/fortran/show/Typed+enumerators and http://docs.cray.com/books/S-3693-36/html-S-3693-36/z1018297010.html show an example of a named enum in Fortran with ISO_C_BINDING.
I cannot build this with Intel 17 or GCC 6.2. Can you please help me understand what I am doing wrong?
! enum.F module enumtest use iso_c_binding #if NAMED_ENUM enum, bind(c) :: color enumerator :: red = 4, blue = 9 enumerator yellow end enum #else enum, bind(c) enumerator :: red = 4, blue = 9 enumerator yellow end enum #endif end module enumtest
$ ifort -std08 -free -g -warn all -traceback -c enum.F $ ifort -std08 -free -g -warn all -traceback -DNAMED_ENUM -c enum.F enum.F(4): error #5082: Syntax error, found '::' when expecting one of: <END-OF-STATEMENT> ; enum, bind(c) :: color --------------------^ enum.F(5): error #6163: This statement is not in the correct order. enumerator :: red = 4, blue = 9 --------^ enum.F(6): error #6163: This statement is not in the correct order. enumerator yellow --------^ enum.F(7): error #8131: An END ENUM statement occurred without a corresponding ENUM statement. end enum ------^ compilation aborted for enum.F (code 1)
$ gfortran-6 -std=f2008 -c enum.F $ gfortran-6 -std=f2008 -DNAMED_ENUM -c enum.F enum.F:4:6: enum, bind(c) :: color 1 Error: Unclassifiable statement at (1) enum.F:5:22: enumerator :: red = 4, blue = 9 1 Error: ENUM definition statement expected before (1) enum.F:6:18: enumerator yellow 1 Error: ENUM definition statement expected before (1) enum.F:7:9: end enum 1 Error: Expecting END MODULE statement at (1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Named enumerations are not part of standard Fortran (2008 or 2015 draft). That wiki page is just a suggestion for future language revisions.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Named enumerations are not part of standard Fortran (2008 or 2015 draft). That wiki page is just a suggestion for future language revisions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Jeff,
Fyi, another thread at comp.lang.fortran - https://groups.google.com/forum/#!msg/comp.lang.fortran/iWUgXY0UJ4s/BlGjDBhlEgAJ;context-place=forum/comp.lang.fortran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Scoped enumerators would be nice, though I do not see a distinction between:
ENUM_TYPE::ENUM_PARAMETER_VAL
and
ENUM_TYPE%ENUM_PARAMETER_VAL
If you wish to remove the scoping, then you could use module scoped parameters
SUBROUTINE ...
USE COLORS
or
SUBROUTINE...
...
BLOCK
USE COLORS
CALL FOO(Red, Green, Blue)
END BLOCK
or
SUBROUTINE...
USE COLORS, RED=>colorRED, ...
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
At the risk of sounding like a broken record - er - a corrupted MP3? - ISO_C_BINDING has nothing whatsoever to do with ENUM, BIND(C) or BIND(C) in general, other than the module and the BIND attribute are both part of C interoperability. Though they have some letters in common, they are not the same thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By the way, your command line for ifort did not include the -fpp option. I am surprised the compiler did not complain about the fpp #'s too.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The .F (capital F) file type causes fpp to be run implicitly on Linux and MacOS. Similar for .F90 (vs .f90)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve Lionel (Intel) wrote:
At the risk of sounding like a broken record - er - a corrupted MP3? - ISO_C_BINDING has nothing whatsoever to do with ENUM, BIND(C) or BIND(C) in general, other than the module and the BIND attribute are both part of C interoperability. Though they have some letters in common, they are not the same thing.
Sorry, Steve, I keep using ISO_C_BINDING as incorrect shorthand for "all the C interoperability stuff in Fortran 2003." I will try to be better about that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove wrote:
By the way, your command line for ifort did not include the -fpp option. I am surprised the compiler did not complain about the fpp #'s too.
Jim Dempsey
I use .F rather than -fpp because other Fortran compilers support the former.
On Mac is that the filesystem is case-insensitive, so one can get into truly horrible situations when trying to rename files from .f to .F and vice versa, so I default to .F since it is obnoxious to change it later, especially when Git is involved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve Lionel (Intel) wrote:
The .F (capital F) file type causes fpp to be run implicitly on Linux and MacOS. Similar for .F90 (vs .f90)
Bad habit (assumption) learned from my earlier Fortran (FORTRAN) programming in Windows.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With some Windows compilers, even if the file is named xyz.f in the directory listing, referring to it as xyz.F in the compiler command line causes the preprocessor to be run. This can be convenient, but it can also be troublesome!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page