Bug 37937 - Bind(C) diagnostic when using c_double for COMPLEX variables
Summary: Bind(C) diagnostic when using c_double for COMPLEX variables
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: diagnostic
Depends on:
Blocks: 32630
  Show dependency treegraph
Reported: 2008-10-28 13:34 UTC by Tobias Burnus
Modified: 2014-06-17 20:29 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2009-03-29 08:39:10


Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-10-28 13:34:53 UTC
REAL(c_double)     matches "double" and is OK. However,
COMPLEX(c_double)  is invalid as the proper kind parameter
                   is c_double_complex matching "double _Complex"

Internally, both yield the same value and also sizeof(0.0_c_double) and sizeof(real(cmplx(0.0, c_double_cmpl)) is the same. Thus one could simply accept c_double as synonym for c_double_complex.

gfortran, however, has checks build in which ensure the right KIND is used; there is room for improvement however:

! ------------------------------
use iso_c_binding
implicit none
real(c_double) :: r
complex(c_double) :: c ! << Wrong
type(c_ptr) :: ptr
ptr = c_loc(c) ! <<< ERROR here
! ------------------------------

Error: C kind parameter is for type REAL but symbol 'c' at (1) is of type COMPLEX

Expected: The error is printed in the "COMPLEX(c_double)" line and not in the "c_loc" line. The other question is whether a WARNING is enough or whether one wants to have an ERROR.

PS: Found at
"    - gfortran 4.3.x does not support complex(c_double)."
Comment 1 Francois-Xavier Coudert 2014-06-17 20:29:59 UTC
First, these are now warnings conditional on -Wc-bind-type (enabled by -Wall). Also, real and complex kinds are now treated as equivalent for this purpose. Has been so since gfortran 4.4, so I'm closing this PR.