# Correctly calling qsort from C

**URL:** <https://fortran-lang.discourse.group/t/correctly-calling-qsort-from-c/1075>\
**Category:** Uncategorized\
**Created:** [April 17, 2021, 3:34am UTC](https://fortran-lang.discourse.group/t/correctly-calling-qsort-from-c/1075 "2021-04-17T03:34:39Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)\
**Post date:** [April 17, 2021, 12:36pm UTC](https://fortran-lang.discourse.group/t/correctly-calling-qsort-from-c/1075/6 "2021-04-17T12:36:29Z")

</div>

> [@gareth](#):
>
> An alternative that might solve the issue in general (?) is to make `stringcompare` take `c_ptr` as arguments …

@gareth,

The prototype for the compare function parameter for `qsort` is

```C
int (*compar)(const void *, const void *)

```

and given this, the Fortran function `interface` shall indeed be `type(c_ptr), intent(in), value`. So it’s not an alternative, it’s the approach to be taken…

---

_[View the full topic](https://fortran-lang.discourse.group/t/correctly-calling-qsort-from-c/1075)._
