Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29269 Discussions

question about non standard definition of attributes on declarations

gauthier_108
Novice
568 Views

I'm dealing with code that has heavy amount of declarations such as

integer(4) :: x[allocatable](:),i

where attributes are put in square brackets after the identifier, and several identifiers that may not share the same attributes are grouped together.

 

I firstly wanted to make sure the example above is 1-to-1 desugaring into:

integer(4), allocatable:: x(:)
integer(4) :: i

 or if I'm misunderstanding something.

 

I'd also like to understand which attributes are valid in the context shown in the first example and if there is documentation about the compiler even supporting this syntax.

For example, this page of the documentation doesn't seem to indicate this placement is possible:

https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2024-2/allocatable.html

 

How does the parser disambiguates with things that can also appear in square bracket after the identifier? I think co-array notation fits this, and maybe there are other things.

 

How is this notation called?

 

The reason I'm trying to understand this is that I intend to contribute updates to https://github.com/camfort/fortran-src so it can support parsing properly the code leveraging this into the AST, and if users desires, pretty-print the appropriate standard notation.

 

I'm sorry if I'm misguided, thanks for any insights!

0 Kudos
4 Replies
Arjen_Markus
Honored Contributor II
538 Views

I have never seen that syntax before and the use of square brackets like this would probably introduce an ambiguity, as square brackets are also used for coarrays. Do you know where the code originated? More specifically, what compiler?

As far as I can tell, not knowing this peculiar syntax, your desugared example seems correct. The allocatable argument is definitely for x only. It resembles in that respect the specification of string lengths:

character*20 x, y*40

you can find in FORTRAN 77 code - the attributes stick to the variable, they do not carry over to all other variables.

0 Kudos
gauthier_108
Novice
534 Views

Thanks Arjen, It is proprietary codebase that probably stem from being built with DEC Visual Fortran lineage.

 

Now that I prompted ChatGPT, apparently, those attributes are supported in same placement:

 

allocatable, automatic, static, volatile, asynchronous and threadprivate.

 

I think things are lining up so my understanding is at least a bit more self confident  

0 Kudos
andrew_4619
Honored Contributor III
486 Views

Definitely not standard Fortran. Ifort gives a standards warning BTW. Never seen that before.

0 Kudos
Steve_Lionel
Honored Contributor III
478 Views

It actually comes from Microsoft Fortran PowerStation; I had thought that had been removed from the Intel compiler years ago, but I guess not.

0 Kudos
Reply