# Fortran sending real pointer to C program: REAL\*8?

**URL:** https://fortran-lang.discourse.group/t/fortran-sending-real-pointer-to-c-program-real-8/3450
**Category:** Uncategorized
**Created:** [May 13, 2022, 3:14pm UTC](https://fortran-lang.discourse.group/t/fortran-sending-real-pointer-to-c-program-real-8/3450 "2022-05-13T15:14:58Z")
**Posts on this page:** 1
**Showing post:** 21

<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: [May 13, 2022, 5:20pm UTC](https://fortran-lang.discourse.group/t/fortran-sending-real-pointer-to-c-program-real-8/3450/21 "2022-05-13T17:20:48Z")

</div>

An acknowledgement in the product, or perhaps a [donation](https://fortran-lang.discourse.group/t/options-for-funding-fortran-lang-projects/3418/11) from you or your employer would be nice, if this is for commercial purposes.

> [@giraffe](#):
>
> Is it okay to do that if the kind of a Fortran real is 4 and the size of a C pointer is larger than 4?

Have you tried it already, and did it work the way you expected? If you’re not willing to do the reading, you can still get far with experimentation:

> **Take a look**
>
> ```cpp
> /* main.c */
> extern void alias_();
> 
> int main(int argc, char const *argv[])
> {
> alias_();
> return 0;
> }
> 
> ```
> 
> ```fortran
> ! alias.f90
> subroutine alias()
> real :: a(3)
> a(1) = transfer(2,a(1))
> a(2) = transfer(4,a(1))
> a(3) = transfer(6,a(1))
> call print_ints_in_c(a(1))
> end subroutine
> 
> ```
> 
> ```cpp
> /* print_ints_in_c_.c */
> #include <stdio.h>
> void print_ints_in_c_(int *a) {
> for (int i = 0; i < 3; i++) {
> printf("a[%d] = %d\n",i, a[i]);
> }
> }
> 
> ```

```txt
$ gfortran -c alias.f90 
$ gcc -c print_ints_in_c_.c 
$ gcc main.c alias.o print_ints_in_c_.o -o main
$ ./main
a[0] = 2
a[1] = 4
a[2] = 6

```

---

_[View the full topic](https://fortran-lang.discourse.group/t/fortran-sending-real-pointer-to-c-program-real-8/3450)._
