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

Scalar to Array character passing

ferrad01
Beginner
605 Views

I have a few occurrences of a scalar character variable being passed into a subroutine expecting a character array:

character*20 title

CALL wrap_kzpwwa(title, 1)

.......

SUBROUTINE wrap_kzpwwa(carr, nel)
integer :: nel
character*(*) :: carr(nel)

This compiles just fine on my machine, but the build machine gives:

"Error: If the actual argument is scalar, the corresponding dummy argument shall be scalar unless the actual argument is an element of an array that is not an assumed-shape or pointer array, or a substring of such an element. [CARR] "

Even if I use the same compiler arguments, I still cannot get it to fail in this way on my machine. Obviously I can fix this by creating another routine which expects a scalar and call that one instead, however I am intrigued as to why this works just fine on my machine but not on another machine. Is there a difference in behavior between different compiler versions? How can I get this to fail on my machine so I can be sure my fixes don't break the overnight build?

Why is this just a problem with character variables?

0 Kudos
3 Replies
DavidWhite
Valued Contributor II
605 Views
You need something more like
CHARACTER(LEN=nel) :: carr
This works if nel is a PARAMETER constant, not sure how it works with an argument variable.
You may need to add
INTEGER, INTENT(IN) :: nel

Regards,

David
0 Kudos
ferrad01
Beginner
605 Views

No NEL is the length of the character string, not the array dimension. Actually I think this is a compiler bug since I have 5 calls to wrap_kzpwwa in the calling routine, and it only fails on the last 2 calls. The only difference is that the first 3 calls are character scalars in external modules while the last 2 (which fail) are local character scalars.

I'll wait for the Intel folk to comment.

0 Kudos
Steven_L_Intel1
Employee
605 Views
It is not a compiler bug, nor is it "just a problem with character variables".

The Fortran language prohibits passing a scalar to an an array, with one exception. You may pass a character scalar to an array of length-1 characters. Your declaration is not that - you would need to say CHARACTER*1 not CHARACTER*(*).

The difference you are seeing is likely due to generated interface checking being on in the case where you get the error and off or unavailable where you don't.
0 Kudos
Reply