Re: ISO_C_BINDING and arrays, optional arguments, etc.
- From: "James Van Buskirk" <not_valid@xxxxxxxxxxx>
- Date: Fri, 4 Feb 2011 09:35:05 -0700
<nmm1@xxxxxxxxx> wrote in message news:iigsjl$fol$1@xxxxxxxxxxxxxxxxxxxxxxx
In article <iiggi0$5qf$1@xxxxxxxxxxxxxxxxxxxxxxxxxx>,
FX <coudert@xxxxxxxxxxxxx> wrote:
Never do this, because no Fortran variable type is interoperable with
_Bool.
Would you care to back this affirmation up? Simple tests show that it
works nicely:
In trivial cases only. If you read the standards more carefully,
you will discover that they are semantically incompatible. Yes,
I know what can be done safely, but I would hate to teach it to
anyone without extensive Fortran, C and interoperability (and
preferably implementation) experience.
Last couple of threads where I drew up some examples I just got
yelled at. In the case of gcc, the C compiler considers zero to
be .FALSE. and everything else to be .TRUE., but the Fortran
compiler considers zero to be .FALSE., one to be .TRUE., and
intentionally abuses you if you put any other value into a LOGICAL
variable. Thus code that read an _Bool value and tells the
Fortran compiler that it's a LOGICAL(C_BOOL) variable may encounter
any kind of mayhem when the optimizer starts composing syllogisms.
On the other hand, reading an _Bool value as an INTEGER(C_INT8_T)
and then testing whether it's nonzero will be safe in gcc. The
way to fix this is for the C compiler to to consider the LSB of
an _Bool variable to be the only significant bit, as the standard
allows, and then to follow suit with the Fortran compiler, but it's
so ingrained in the mindset of the C programmer that zero is .FALSE.
and everything else is .TRUE. that this situation will never happen
no matter how error-prone it is. Time for the yelling, I suppose.
But if you do that I will just have to put another Yes album on
and turn the volume way up so that I can't hear you any more.
A lot of the Fortran interoperability section is a serious error,
because it does not have well-defined properties.
Could you be kind enough to point out maybe a couple of the most
glaring cases?
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
.
- Follow-Ups:
- References:
- ISO_C_BINDING and arrays, optional arguments, etc.
- From: vincenzo
- Re: ISO_C_BINDING and arrays, optional arguments, etc.
- From: James Van Buskirk
- Re: ISO_C_BINDING and arrays, optional arguments, etc.
- From: FX
- Re: ISO_C_BINDING and arrays, optional arguments, etc.
- From: nmm1
- ISO_C_BINDING and arrays, optional arguments, etc.
- Prev by Date: Re: Composite assignment operators in Fortran
- Next by Date: Re: ISO_C_BINDING and arrays, optional arguments, etc.
- Previous by thread: Re: ISO_C_BINDING and arrays, optional arguments, etc.
- Next by thread: Re: ISO_C_BINDING and arrays, optional arguments, etc.
- Index(es):
Relevant Pages
|