- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Is the program below legal?
program test1
use, intrinsic :: iso_c_binding, only: c_loc
implicit none
type :: foo
integer :: b(3)
end type
type(foo), target :: x
class(foo), pointer :: p
! Potentially illegal, fptr should be nonpolymorphic
call c_f_pointer(cptr=c_loc(x), fptr=p)
! J3/24-007, page 504, L40-L42, Case (ii)
! If the value of CPTR is the result of a reference to C_LOC with
! a noninteroperable effective argument X, FPTR shall be a nonpolymorphic pointer
! with the same type and type parameters as X.
print *, same_type_as(p, x)
end program
With ifort the program prints "true". With ifx 2025.3 it also prints "true". Is this behavior portable?
I see one potential loophole if the association is covered by Case (iii) of `c_f_pointer` (J3/24-007, page 505), i.e.
"If the value of CPTR is the C address of a storage sequence that is not in use by any other Fortran entity, FPTR becomes associated with that storage sequence. The storage sequence shall be large enough to contain the target object described by FPTR and shall satisfy any other processor-dependent requirement for association."
Could anyone clarify if this is the case here?
Lien copié
0 Réponses
Répondre
Options du sujet
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable