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

Allocatable array with 0 base?

Adrian_F_1
Beginner
583 Views

Is it possible to allocate an array, but have 0 as its base?

I know non-allocatable is easy with integer :: fred(0:10)

But I'm not sure how to do it with an allocatable array

0 Kudos
4 Replies
Arjen_Markus
Honored Contributor I
583 Views

Not much different than with declarations:

allocate( fred(0:10) )

 

 

 

0 Kudos
Adrian_F_1
Beginner
583 Views

Arjen Markus wrote:

Not much different than with declarations:

allocate( fred(0:10) )

oh dear, I'm sure I tried that a few months ago and it didn't work.  anyway works fine now thanks

0 Kudos
Steven_L_Intel1
Employee
583 Views

Make sure you didn't try something like this:

real, allocatable :: fred(0:)
...
allocate (fred(0:10))

The declaration of fred has to be with (:) - no lower bound. If you have a lower bound, then it can't be allocatable (could be a dummy argument.)

0 Kudos
Adrian_F_1
Beginner
583 Views

Steve Lionel (Intel) wrote:

Make sure you didn't try something like this:

real, allocatable :: fred(0:)
...
allocate (fred(0:10))

The declaration of fred has to be with (:) - no lower bound. If you have a lower bound, then it can't be allocatable (could be a dummy argument.)

I may well have done that.  Thanks for the heads up.

0 Kudos
Reply