Command line Compiler Explorer

A Linux command line compiler explorer script inspired by this article by Matt Godbolt. See the repo that generated this page.


sudo apt update
sudo apt install g++ curl entr gedit

git clone
cd explore/

Example usage

Below I’m splitting my terminal with tmux and running the main script when the source changes using entr.

ls main.cxx | entr -c bash

But you can also use this wrapper script to edit in gedit.


The bash script

This command really is the core of, edit your compiler flags here.

readonly CXXFLAGS="-std=c++23 -O1"

g++ main.cxx $CXXFLAGS -S -o - \
    | c++filt \
    | grep -vE "\s+\.|^[0-9]:"

The source file main.cxx

#include <cmath>
#include <cstddef>

int func(const size_t max) {

  int sum = 0;

  for (auto i = 0uz; i < max; ++i)
    sum += i;

  return sum;

int main() {
  const auto param = std::pow(2, 13);
  return func(param * 3);

The generated assembly

Note the call to std::pow has been optimised out even at -O1.

func(unsigned long):
    testq   %rdi, %rdi
    movl    $0, %eax
    movl    $0, %edx
    addl    %eax, %edx
    addq    $1, %rax
    cmpq    %rax, %rdi
    movl    %edx, %eax
    movl    $0, %edx
    movl    $24576, %edi
    call    func(unsigned long)