Bonjour,
J'ai une incohérence de résultat quand j'utilise la fonction "present", et donc il semblerait que je l'utilise mal ; pouvez-vous me dire ce qui ne va pas sur ce mini exemple ?
1 2 3 4 5 6 7 8 9 10 11 12
| SUBROUTINE OPT(a,n)
IMPLICIT NONE
INTEGER , INTENT(IN), OPTIONAL :: n
INTEGER , INTENT(OUT) :: a
IF (present(n)) THEN
a= 2
ELSE
a=0
ENDIF
RETURN
END |
1 2 3 4 5 6 7 8 9 10 11
| PROGRAM MAINPRICE
IMPLICIT NONE
INTEGER :: a
EXTERNAL OPT
CALL OPT(a)
PRINT*, "a=", a
END PROGRAM MAINPRICE |
Je compile avec gfortran en mode debug:
gfortran -g -o test OPT.F90 TESTOPTIONAL.F90
et mon résultat est différent suivant que j'utilise valgrind ou pas !!
et :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| valgrind --tool=memcheck ./test
==6422== Memcheck, a memory error detector
==6422== Copyright (C) 2002-2013, and GNU GPL d, by Julian Seward et al.
==6422== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==6422== Command: ./test
==6422==
a= 0
==6422==
==6422== HEAP SUMMARY:
==6422== in use at exit: 0 bytes in 0 blocks
==6422== total heap usage: 21 allocs, 21 frees, 11,821 bytes allocated
==6422==
==6422== All heap blocks were freed -- no leaks are possible
==6422==
==6422== For counts of detected and suppressed errors, rerun with: -v
==6422== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) |
Merci beaucoup !
Partager