Thanks for using Compiler Explorer
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
c source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
AArch64 (Morello compiler)
Hybrid CHERI-MIPS
Hybrid CHERI-RISCV64
Hybrid Morello
MIPS (without CHERI)
Purecap CHERI-MIPS
Purecap CHERI-RISCV64
Purecap Morello
RISCV64 (without CHERI)
Options
Source code
#include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <time.h> #define seq_t uint32_t* __capability // The __capability qualifier here is not necessary when compiling for "pure" mode // (because all pointers have capabilities in "pure" mode), but might be needed // if compiling for "hybrid" mode, so has been left in for convenience and clarity. #define SEQ_LEN 15 void populate (seq_t __cheri_output sequence, int size); void print (seq_t __cheri_input sequence, int size); void sort (seq_t sequence, int size); void swap (seq_t first, seq_t second); int main (void) { printf("Morello bare-metal bubble sort example\n\n"); seq_t sequence = (__cheri_tocap seq_t)malloc(sizeof(uint32_t) * SEQ_LEN); populate(sequence, SEQ_LEN); printf("Original sequence:\n "); print(sequence, SEQ_LEN); sort(sequence, SEQ_LEN); printf("Sorted sequence:\n "); print(sequence, SEQ_LEN); free((__cheri_fromcap void*)sequence); return 0; } void populate (seq_t __cheri_output sequence, int size) { srand(time(NULL)); for (int i = 0; i < size; i++) { sequence[i] = rand() % (101); } } void print (seq_t __cheri_input sequence, int size) { for (int i = 0; i < size; i++) { if (i > 0) { printf(", "); } printf("%d", sequence[i]); } printf("\n"); } void sort (seq_t sequence, int size) { for (int i = 0; i < (size - 1); i++) { for (int j = 0; j < (size - i - 1); j++) { if (sequence[j] > sequence[j+1]) { swap(&sequence[j], &sequence[j+1]); } } } } void swap (seq_t first, seq_t second) { uint32_t temp = *first; *first = *second; *second = temp; }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
About the author
Statistics
Changelog
Version tree