Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions flang-rt/lib/runtime/extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <cstring>
#include <ctime>
#include <signal.h>
#include <stdlib.h>
#include <thread>

#ifdef _WIN32
Expand Down Expand Up @@ -262,5 +263,10 @@ int RTNAME(Chdir)(const char *name) {

int FORTRAN_PROCEDURE_NAME(ierrno)() { return errno; }

void FORTRAN_PROCEDURE_NAME(qsort)(int *array, int *len, int *isize,
int (*compar)(const void *, const void *)) {
qsort(array, *len, *isize, compar);
}

} // namespace Fortran::runtime
} // extern "C"
31 changes: 31 additions & 0 deletions flang/docs/Intrinsics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1106,3 +1106,34 @@ end program chdir_func
- **Standard:** GNU extension
- **Class:** function
- **Syntax:** `RESULT = IERRNO()`

### Non-Standard Intrinsics: QSORT

#### Description

```
SUBROUTINE QSORT(ARRAY, LEN, ISIZE, COMPAR)
TYPE(*) :: ARRAY(*)
INTEGER(4) :: LEN, ISIZE
INTERFACE
INTEGER(4) FUNCTION COMPAR(A, B)
TYPE(*) :: A, B
END FUNCTION
END INTERFACE
END SUBROUTINE
```

Sort `ARRAY` in place in ascending order given the comparison function `COMPAR`.
The array number of elements is given by `LEN` and the element byte size is given
by `ISIZE`.

`COMPAR` function takes the addresses of element `A` and `B` and must return:
- a negative value if `A` < `B`
- zero if `A` == `B`
- a positive value otherwise.

#### Usage and Info

- **Standard:** lib3f (section 3f of old man pages).
- **Class:** subroutine
- **Syntax:** `CALL QSORT(ARRAY, LEN, ISIZE, COMPAR)`