In C/C++, the standard syntax for pragmas is:
#pragma ...
In Fortran, what is the most common syntax for this? The wikipedia article on pragmas (directives) does not mention Fortran: Directive (programming) - Wikipedia
The only relevant discussion at fortran-proposals github that I was able to find: Option to have interoperable types packed · Issue #256 · j3-fortran/fortran_proposals · GitHub
Here are the styles of pragmas I was able to find on the internet:
C$PRAGMA SUN PIPELOOP=0
: Directives (Fortran User's Guide)!$omp parallel do collapse(2) default(shared)
: [2110.10151] Can Fortran's 'do concurrent' replace directives for accelerated computing?!DEC$ attributes dllexport :: xxx
: Standard-conforming way of doing `!DEC$ attributes dllexport`!GCC$ ATTRIBUTES attribute-list :: variable-list
: ATTRIBUTES directive (The GNU Fortran Compiler)
It seems the established syntax is to use a comment (C
in fixed-form, or !
in free-form) followed by $
. And sometimes there is a compiler vendor/name in between.
In particular, what would be a good way to add new attributes to variable declaration, that are language extensions? Let’s say you wanted to add a simd
extension to LFortran (SIMD backend · Issue #2293 · lfortran/lfortran · GitHub). The obvious choice is:
real(sp), simd :: x(8)
And I think this is the way to do it, if you are ok to only use LFortran. However, it is often useful to be able to compile the same code with multiple compilers. So in addition to the above, we should also support pragma directives, and users have a choice. Given my research above, what would be the most natural way?
Here is the best idea I have so far, in order to be as compatible as possible with established usage:
!LF$ attributes simd :: x
real(sp) :: x(8)
Here LF
stands for LFortran. And the syntax otherwise is like for GFortran or Intel Fortran for adding custom attributes. If later let’s say GFortran supports it as well, we could do:
!GCC$ attributes simd :: x
!LF$ attributes simd :: x
real(sp) :: x(8)
What syntax would you recommend?