# GNU very simple interoperable c Fortran module integer demo segfault

**URL:** <https://fortran-lang.discourse.group/t/gnu-very-simple-interoperable-c-fortran-module-integer-demo-segfault/10693>\
**Category:** Help\
**Created:** [February 3, 2026, 10:03pm UTC](https://fortran-lang.discourse.group/t/gnu-very-simple-interoperable-c-fortran-module-integer-demo-segfault/10693 "2026-02-03T22:03:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gWyche](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gWyche](https://fortran-lang.discourse.group/u/gWyche)\
**Post date:** [February 3, 2026, 10:03pm UTC](https://fortran-lang.discourse.group/t/gnu-very-simple-interoperable-c-fortran-module-integer-demo-segfault/10693/1 "2026-02-03T22:03:37Z")

</div>

I just want one that works. I even updated bookworm, then installed Trixie and still got the same error (except the number before the word Segmentation changes). All this code (case changes are mine) comes from tries with Chrome’s AI question answer (on 2 different days). It _looks_ very simple.

I did find “Security update for GLIBC for a risk 1st noted in 2018 and an accepted alteration last year + a comment that the fix broke (old code). No comment about what code uses it. I have written lots of interoperable demo programs for functions and subroutines, but NEVER had a segmentation fault with them. I really don’t want to abandon the idea of a global module’s interoperable storage type is not currently doable.

How might I go about understanding where this segmentation comes from? [I don’t have any C program debugging experience beyond printf statements.]

$ cat fortran\_module.f90  
MODULE fortran\_module  
USE, INTRINSIC :: ISO\_C\_BINDING  
IMPLICIT NONE  
INTEGER(C\_INT), BIND(C, name=“c\_access\_int”) :: fortran\_int  
CONTAINS  
SUBROUTINE set\_fortran\_int(value) BIND(C, name=“set\_fortran\_int”)  
INTEGER(C\_INT), INTENT(IN) :: value  
fortran\_int = value  
END SUBROUTINE set\_fortran\_int  
END MODULE fortran\_module

$ cat c\_program.c  
#include \<stdio.h\>  
extern int c\_access\_int;  
extern void set\_fortran \_int(int\_value);

int main(void) {  
printf(“Initial value of the Fortran integer: %d\n”, c\_access\_int);  
c\_access\_int = 42;  
printf(“Value after direct C modification: %d\n”, c\_access\_int);  
set\_fortran\_int(99);  
printf(“value after modification by Fortran subroutine: %d\n”, c\_access\_int);  
return 0;  
}

$ cat compile\_link\_and\_run.bash  
#! /bin/bash  
gfortran -c fortran\_module.f90  
gcc -c c\_program.c  
gfortran c\_program.o fortran\_module.o -o mixed\_program  
./mixed\_program  
-------- output ------ of that  
Initial value of the Fortran integer: 0  
Value after direct C modification: 42  
./compile\_link\_and\_run.bash: line 5: 5087 Segmentation fault ./mixed\_program

$nm -u mixed\_program  
w \_ITM\_deregisterTMCloneTable  
w \_ITM\_registerTMCloneTable  
w \_\_cx\_finalize@GLIBC\_2.2.5  
w \_\_gmon\_start  
U \_\_libc\_start\_main@GLIBC\_2.34  
U \_\_ printf@GLIBC\_2.2.5

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [February 3, 2026, 10:16pm UTC](https://fortran-lang.discourse.group/t/gnu-very-simple-interoperable-c-fortran-module-integer-demo-segfault/10693/2 "2026-02-03T22:16:22Z")

</div>

> [@gWyche](#):
>
> ```patch
> SUBROUTINE set_fortran_int(value) BIND(C, name="set_fortran_int")
> -INTEGER(C_INT), INTENT(IN) :: value
> +INTEGER(C_INT), INTENT(IN), VALUE :: value
> fortran_int = value
> END SUBROUTINE set_fortran_int
> 
> ```

This should do the trick.

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [February 3, 2026, 10:20pm UTC](https://fortran-lang.discourse.group/t/gnu-very-simple-interoperable-c-fortran-module-integer-demo-segfault/10693/3 "2026-02-03T22:20:07Z")

</div>

> [@gWyche](#):
>
> printf(“Initial value of the Fortran integer: %d\n”, c\_access\_int);

Btw, use of an unitialized variable is not a portable practice and can be dangerous: [CWE - CWE-457: Use of Uninitialized Variable (4.19.1)](https://cwe.mitre.org/data/definitions/457.html)

You can set an initial value for portability:

```auto
INTEGER(C_INT), BIND(C, name=“c_access_int”) :: fortran_int = 0

```

---

<div class="post-metadata">

**Author:** ![gWyche](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gWyche](https://fortran-lang.discourse.group/u/gWyche)\
**Post date:** [February 3, 2026, 10:42pm UTC](https://fortran-lang.discourse.group/t/gnu-very-simple-interoperable-c-fortran-module-integer-demo-segfault/10693/4 "2026-02-03T22:42:40Z")

</div>

Yes those suggestions made it work.

The $ nm stuff must be a “red herring” for me, so the report stayed the same.

I have not tried to “correct” a Chrome AI wrong answer. Do you think that if I ask my question by adding without “, VALUE” would be helpful or maybe saying, “Do I have to use ‘pass by value’?”

I don’t understand how much Interoperabilty coding is done for us. I would have thought that as much as we are told that c expects value so one or the other of Fortran or C _must_ accommodate that expectation. That seemed to be relaxed in later versions of interoperability .. at least when doing functions and subroutines .. because all that is needed is an asterisk in front of the variable(s) in the c code. The AI missed that when showing the 2 Fortran examples (or possibly I am blind to its poor choice of naming the Fortran variable …..value….. !

Thank you for such swift help. I can go home and rest without JOTS (jobbing on the sleep).

George Wyche
