Some compilers store metadata of the array in a dope array descriptor, including attributes like allocatability, contiguity, element storage size, definition status, if it's a pointer... They are needed internally by the language to check interface matching on specific procedure calls.
So, it's technically possible to inspect this kind of meta information, but it's also hardly useful to do so. Again, Fortran is statically typed and the compiler is able to do all this checks at compile-time.
Moreover, the language is designed in a way that you can only handle allocation on a variable (or a dummy argument) when you explicitly declared it to be allocatable (or pointer). In all other cases, you can use an array without bothering how it was allocated.
See this forum thread:
Once you have allocated an allocatable array, it is now an array as "good" as any other and it can be passed as an actual argument to procedures (or C
functions) that don't even need to know that it is allocatable. The same applies to pointer arrays, I might add, though there is one slight caveat to that case (involving the possibility that a pointer array
might point to a non-contiguous slice).
For your specific case, you are trying to use the intrinsic function allocated
with a non-allocatable array y
, giving the error. You don't need to check if an array is allocatable before using this function on it, you just need to know that, if you didn't explicity declare it as allocatable
(as you did with x
), it is not.
Same way, if you want to manage allocation of a variable inside a function or subroutine, you just need to declare the dummy argument as allocatable, and you are guaranteed that only allocatable variables will be accepted by the procedure (same with pointers).
If, by any chance, you have strong reasons to poke with internal representation of variables and you know what you're doing, you can refer to this answer from @VladmirF on other question or dive into the reference manual of your specific compiler. Also, recent versions of the standard specify a standardized array descriptor, aiming interoperability with c code.
Lastly, as you tagged Intel in this question, I'll point you to the Intel compiler reference on the matter, where you can see that:
The downside to using array descriptors is that it can increase the opportunity for errors. Additionally, the corresponding code is not portable. Specifically:
If the descriptor is not defined correctly, the program may access the wrong memory address, possibly causing a General Protection Fault.
Array descriptor formats are specific to each Fortran compiler. Code that uses array descriptors is not portable to other compilers or platforms.
The array descriptor format may change in the future.
If the descriptor was built by the compiler, it cannot be modified by the user. Changing fields of existing descriptors is illegal.
The components of the current Intel® Fortran array descriptor on systems using IA-32 architecture are as follows:
Bytes 0 to 3 contain the base address.
(...)
Bytes 12 to 15 contain a set of flags used to store information about the array. This includes:
bit 1 (0x01): array is defined -- set if the array has been defined (storage allocated).
(...)
bit 8 (0x80): set if the array pointed to is ALLOCATABLE.
Other bits are reserved.