I don’t think it is possible in the general case, to tell if the cptr is pointing to a scalar or array. But I guess one could assume that is what the user wanted from the fptr argument, and give an error “missing shape argument; argument fptr is a rank-1 array” or something like that.
Edit: I see other compilers do this:
GCC:
> gfortran --version
GNU Fortran (SUSE Linux) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> gfortran test_c_f_pointer.f90
test_c_f_pointer.f90:11:36:
call c_f_pointer( c_loc(a(98)), p ) ! non standard conforming
1
Error: Expected SHAPE argument to C_F_POINTER with array FPTR at (1)
>
NAG:
> nagfor test_c_f_pointer.f90
NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7203
Error: test_c_f_pointer.f90, line 11: No specific match for reference to generic C_F_POINTER
[NAG Fortran Compiler error termination, 1 error]
flang:
error: Semantic errors in /app/example.f90
/app/example.f90:11:5: error: SHAPE= argument to C_F_POINTER() must appear when FPTR= is an array
call c_f_pointer( c_loc(a(98)), p ) ! non standard conforming
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compiler returned: 1
nvfortran:
NVFORTRAN-S-0074-Illegal number or type of arguments to c_f_pointer - keyword argument fptr (/app/example.f90: 11)
0 inform, 0 warnings, 1 severes, 0 fatal for MAIN
Compiler returned: 2
Kind of cryptic warning with nvfortran.