Compiler Explorer

App · 12 actions

Compile code with thousands of compilers on Compiler Explorer (godbolt.org) and see the assembly, build and run programs with input, run analysis tools such as clang-tidy, format code, share it as a short link, and look up what an instruction does. No account or API key required.

Actions

ActionWhat it does
Compile and run codeBuild a program and run it once on Compiler Explorer, with the input and command-line arguments you give, and get what it printed and its exit code.
Compile codeCompile code with the compiler and flags you choose and get the assembly it produces, with the compiler's errors and warnings line by line.
Create short linkSave code with its compiler, flags and libraries as a godbolt.org/z/ link that opens it in Compiler Explorer, optionally with the program running.
Format codeReformat code with clang-format (in the Google, LLVM or another style), rustfmt, gofmt or another formatter, choosing spaces or tabs and the indent width.
Get instruction documentationLook up what an assembly instruction does, such as imul on x86-64 or ldr on ARM, from the vendor's reference, with a link to the full entry.
Get short linkRead the code, language, compilers, flags and libraries saved in a godbolt.org/z/ short link.
List code formattersList the code formatters Compiler Explorer runs, such as clang-format, rustfmt and gofmt, with their versions and the styles each offers.
List compilersList compilers, for one language or all, with each one's ID, version, target instruction set and release track.
List languagesList the programming languages Compiler Explorer supports, with each one's ID, file extensions, default compiler, formatter, and whether its programs can be run.
List librariesList the libraries code in a language can include on Compiler Explorer, such as {fmt} or Boost for C++, with their versions.
List toolsList the analysis tools that can run over a language's code, such as clang-tidy, llvm-mca, pahole or readelf for C++, and whether each reads input.
Run analysis toolCompile code and run one analysis tool over it, such as clang-tidy to find likely bugs, llvm-mca to estimate cycles or include-what-you-use to tidy includes.

Compile and run code

Build a program and run it once on Compiler Explorer, with the input and command-line arguments you give, and get what it printed and its exit code. A build that fails comes back with the compiler's errors and 'ran' false.

Inputs

LanguagelanguagetextRequired
The programming language of the code.
CompilercompilertextRequired
The compiler to use, such as x86-64 gcc 16.2. Choose the language first to list its compilers.
CodesourcetextRequired
The code, as you would paste it into Compiler Explorer.
Compiler flagsoptionstext
Flags for the compiler, such as -O2 -Wall -std=c++20.
Program inputstdintext
Text the program reads from standard input.
Program argumentsargumentstext
Command-line arguments, separated by spaces. Quote one that contains spaces, as in --name "Jo Bloggs".
Librarieslibrarieslist
Libraries the code includes, such as {fmt} or Boost. Choose the language first to list them.

Outputs

buildobject
How the build went
compilertext
The compiler ID used
exit_codenumber
The program's exit code; empty when it did not run
languagetext
The language ID used
rantrue/false
True when the program ran; false when the build failed
run_time_msnumber
How long the program ran, in milliseconds
stderrtext
What the program printed to standard error
stdouttext
What the program printed to standard output
summarytext
One line saying what came back
timed_outtrue/false
True when the program ran out of time and was stopped
truncatedtrue/false
True when the output was too long and was cut short
Example output
{
  "build": {
    "diagnostics": [],
    "error_count": 0,
    "exit_code": 0,
    "stderr": "",
    "stdout": "",
    "success": true,
    "warning_count": 0
  },
  "compiler": "g162",
  "exit_code": 0,
  "language": "c++",
  "ran": true,
  "run_time_ms": 24,
  "stderr": "",
  "stdout": "hello world",
  "summary": "The program ran and exited with code 0, printing 1 line.",
  "timed_out": false,
  "truncated": false
}

Compile code

Compile code with the compiler and flags you choose and get the assembly it produces, with the compiler's errors and warnings line by line. Code that fails to compile comes back with 'success' false rather than failing the step.

Inputs

LanguagelanguagetextRequired
The programming language of the code.
CompilercompilertextRequired
The compiler to use, such as x86-64 gcc 16.2. Choose the language first to list its compilers.
CodesourcetextRequired
The code, as you would paste it into Compiler Explorer.
Compiler flagsoptionstext
Flags for the compiler, such as -O2 -Wall -std=c++20.
Output filtersfilterslist
Which of Compiler Explorer's output filters to turn on. Leave empty for its defaults: Intel syntax and demangled names, with unused labels, directives and comment-only lines hidden.One or more of: intel (Intel syntax (x86)), demangle (Demangle names), labels (Hide unused labels), directives (Hide directives), commentOnly (Hide comment-only lines), libraryCode (Hide library functions), trim (Trim extra whitespace), debugCalls (Hide debug intrinsics), binaryObject (Compile to an object file and disassemble it), binary (Link to a binary and disassemble it).
Librarieslibrarieslist
Libraries the code includes, such as {fmt} or Boost. Choose the language first to list them.

Outputs

assemblytext
The assembly the compiler produced, one line per line
assembly_line_countnumber
How many lines of assembly
compile_time_msnumber
How long compiling took, in milliseconds
compilertext
The compiler ID used
diagnosticslist
Each error, warning and note, with its line
error_countnumber
How many errors
exit_codenumber
The compiler's exit code: 0 when it succeeded
instruction_settext
What the assembly is for, such as amd64
languagetext
The language ID used
stderrtext
What the compiler printed to standard error: its messages
stdouttext
What the compiler printed to standard output
successtrue/false
True when the code compiled
summarytext
One line saying what came back
timed_outtrue/false
True when the compiler ran out of time
truncatedtrue/false
True when the output was too long and was cut short
warning_countnumber
How many warnings
Example output
{
  "assembly": "\"square(int)\":\n        imul    edi, edi\n        mov     eax, edi\n        ret",
  "assembly_line_count": 4,
  "compile_time_ms": 40,
  "compiler": "g162",
  "diagnostics": [],
  "error_count": 0,
  "exit_code": 0,
  "instruction_set": "amd64",
  "language": "c++",
  "stderr": "",
  "stdout": "",
  "success": true,
  "summary": "g162 compiled the code, no warnings; 4 lines of assembly.",
  "timed_out": false,
  "truncated": false,
  "warning_count": 0
}

Save code with its compiler, flags and libraries as a godbolt.org/z/ link that opens it in Compiler Explorer, optionally with the program running. Links are permanent and anyone who has one can see the code.

Inputs

LanguagelanguagetextRequired
The programming language of the code.
CompilercompilertextRequired
The compiler to use, such as x86-64 gcc 16.2. Choose the language first to list its compilers.
CodesourcetextRequired
The code, as you would paste it into Compiler Explorer.
Compiler flagsoptionstext
Flags for the compiler, such as -O2 -Wall -std=c++20.
Librarieslibrarieslist
Libraries the code includes, such as {fmt} or Boost. Choose the language first to list them.
Show the program runningrun_programtrue/false
Add a pane that runs the program, with the input and arguments below.
Program inputstdintext
Text the program reads from standard input.
Program argumentsargumentstext
Command-line arguments, separated by spaces. Quote one that contains spaces, as in --name "Jo Bloggs".

Outputs

idtext
The link's ID, the part after /z/
summarytext
One line saying what came back
urltext
The link, such as https://godbolt.org/z/E9Escj1EY
Example output
{
  "id": "E9Escj1EY",
  "summary": "Saved as https://godbolt.org/z/E9Escj1EY.",
  "url": "https://godbolt.org/z/E9Escj1EY"
}

Format code

Reformat code with clang-format (in the Google, LLVM or another style), rustfmt, gofmt or another formatter, choosing spaces or tabs and the indent width.

Inputs

FormatterformattertextRequired
The formatter: clangformat for C and C++, rustfmt, gofmt...
CodesourcetextRequired
The code, as you would paste it into Compiler Explorer.
Stylestyletext
The base style, for formatters that have them (clang-format: Google, LLVM, Mozilla...). Defaults to the formatter's first.
Indent with spacesuse_spacestrue/false
Indent with spaces rather than tabs. Defaults to on.
Indent widthtab_widthnumber
How many columns one indent is, 1 to 16. Defaults to 4.From 1 to 16.

Outputs

changedtrue/false
True when formatting changed the code
formattedtext
The formatted code
formattertext
The formatter used
styletext
The base style used, if the formatter has styles
summarytext
One line saying what came back
Example output
{
  "changed": true,
  "formatted": "int main() { int x = 1; }",
  "formatter": "clangformat",
  "style": "Google",
  "summary": "clangformat reformatted the code."
}

Get instruction documentation

Look up what an assembly instruction does, such as imul on x86-64 or ldr on ARM, from the vendor's reference, with a link to the full entry.

Inputs

Instruction setinstruction_settextRequired
The processor family, or bytecode, the instruction is for.One of: amd64 (x86-64 (amd64)), aarch64 (ARM 64-bit (AArch64)), arm32 (ARM 32-bit), riscv64 (RISC-V 64-bit), powerpc, avr, 6502 (MOS 6502), llvm (LLVM IR), ptx (NVIDIA PTX), sass (NVIDIA SASS), and 3 more.
InstructionopcodetextRequired
The instruction's mnemonic, such as imul, ldr or addi.

Outputs

descriptiontext
The full explanation, as plain text
htmltext
The full explanation as the reference's HTML
instruction_settext
The instruction set it is from
opcodetext
The instruction looked up
summarytext
A one-paragraph explanation
urltext
A link to the reference's entry
Example output
{
  "description": "Performs a signed multiplication of two operands. This instruction has three forms, depending on the number of operands.",
  "html": "<p>Performs a signed multiplication of two operands. This instruction has three forms, depending on the number of operands.</p>",
  "instruction_set": "amd64",
  "opcode": "imul",
  "summary": "Performs a signed multiplication of two operands. This instruction has three forms, depending on the number of operands.",
  "url": "https://www.felixcloutier.com/x86/imul"
}

Read the code, language, compilers, flags and libraries saved in a godbolt.org/z/ short link.

Inputs

Short linklinktextRequired
The link, such as https://godbolt.org/z/E9Escj1EY, or just its ID.

Outputs

compilertext
The first compiler's ID
idtext
The link's ID
languagetext
The first editor's language ID
optionstext
The first compiler's flags
session_countnumber
How many editors
sessionslist
Every editor in the link, with its compilers
sourcetext
The first editor's code
summarytext
One line saying what came back
urltext
The link
Example output
{
  "compiler": "g162",
  "id": "E9Escj1EY",
  "language": "c++",
  "options": "-O2",
  "session_count": 1,
  "sessions": [
    {
      "compilers": [
        {
          "compiler": "g162",
          "libraries": [],
          "options": "-O2"
        }
      ],
      "executors": [
        {
          "arguments": "",
          "compiler": "g162",
          "libraries": [],
          "options": "-O2",
          "stdin": ""
        }
      ],
      "language": "c++",
      "source": "int square(int n) { return n * n; }\n"
    }
  ],
  "source": "int square(int n) { return n * n; }\n",
  "summary": "1 editor of c++ code with 1 compiler.",
  "url": "https://godbolt.org/z/E9Escj1EY"
}

List code formatters

List the code formatters Compiler Explorer runs, such as clang-format, rustfmt and gofmt, with their versions and the styles each offers.

Inputs

None.

Outputs

countnumber
How many are listed
formatterslist
The formatters
summarytext
One line saying what came back
Example output
{
  "count": 1,
  "formatters": [
    {
      "name": "clangformat",
      "styles": [
        "Google",
        "LLVM",
        "Mozilla",
        "Chromium",
        "WebKit"
      ],
      "type": "clangformat",
      "version": "clang-format version 24.0.0git"
    }
  ],
  "summary": "1 formatter: clangformat."
}

List compilers

List compilers, for one language or all, with each one's ID, version, target instruction set and release track. Narrow it by name (clang, x86-64 gcc), to stable or nightly builds, or to compilers whose programs can be run.

Inputs

Languagelanguagetext
Only compilers for this language. Leave empty for all.
Name containsname_containstext
Only compilers whose name or ID contains this, such as clang.
Release trackrelease_tracktext
Only stable releases, nightly builds and so on.One of: stable (Stable releases), nightly (Nightly builds (trunk)), prerelease (Pre-releases), experimental.
Only those that can run programsrunnable_onlytrue/false
Only compilers whose programs Compiler Explorer can run.
Most to returnlimitnumber
How many compilers to return, 1 to 1000. Defaults to 100.From 1 to 1000.

Outputs

compilerslist
The compilers that matched
countnumber
How many are listed
summarytext
One line saying what came back
total_countnumber
How many matched in all, before the limit
Example output
{
  "compilers": [
    {
      "can_run_programs": true,
      "compiler_type": null,
      "group": "GCC x86-64",
      "id": "g162",
      "instruction_set": "amd64",
      "language": "c++",
      "name": "x86-64 gcc 16.2",
      "release_track": "stable",
      "version": "16.2"
    }
  ],
  "count": 1,
  "summary": "1 compiler for c++ matched.",
  "total_count": 1
}

List languages

List the programming languages Compiler Explorer supports, with each one's ID, file extensions, default compiler, formatter, and whether its programs can be run.

Inputs

None.

Outputs

countnumber
How many are listed
languageslist
The languages, by name
summarytext
One line saying what came back
Example output
{
  "count": 1,
  "languages": [
    {
      "can_run_programs": true,
      "default_compiler": "g162",
      "example": "int square(int num) {\n    return num * num;\n}",
      "extensions": [
        ".cpp",
        ".cxx",
        ".h",
        ".hpp",
        ".cc"
      ],
      "formatter": "clangformat",
      "id": "c++",
      "name": "C++"
    }
  ],
  "summary": "Compiler Explorer supports 1 language."
}

List libraries

List the libraries code in a language can include on Compiler Explorer, such as {fmt} or Boost for C++, with their versions.

Inputs

LanguagelanguagetextRequired
The programming language.
Name containsname_containstext
Only libraries whose name, ID or description contains this.

Outputs

countnumber
How many are listed
librarieslist
The libraries
summarytext
One line saying what came back
Example output
{
  "count": 1,
  "libraries": [
    {
      "description": "A modern formatting library",
      "id": "fmt",
      "latest_value": "fmt@1200",
      "latest_version": "12.0.0",
      "name": "{fmt}",
      "url": "https://fmt.dev/",
      "versions": [
        {
          "id": "1100",
          "version": "11.0.0"
        },
        {
          "id": "1200",
          "version": "12.0.0"
        },
        {
          "id": "trunk",
          "version": "trunk"
        }
      ]
    }
  ],
  "summary": "1 library for c++."
}

List tools

List the analysis tools that can run over a language's code, such as clang-tidy, llvm-mca, pahole or readelf for C++, and whether each reads input.

Inputs

LanguagelanguagetextRequired
The programming language.

Outputs

countnumber
How many are listed
summarytext
One line saying what came back
toolslist
The tools
Example output
{
  "count": 1,
  "summary": "1 tool for c++.",
  "tools": [
    {
      "accepts_input": false,
      "id": "clangtidytrunk",
      "name": "clang-tidy (trunk)",
      "type": "independent"
    }
  ]
}

Run analysis tool

Compile code and run one analysis tool over it, such as clang-tidy to find likely bugs, llvm-mca to estimate cycles or include-what-you-use to tidy includes. Returns the tool's output and the messages it tied to lines of the code.

Inputs

LanguagelanguagetextRequired
The programming language of the code.
CompilercompilertextRequired
The compiler to use, such as x86-64 gcc 16.2. Choose the language first to list its compilers.
TooltooltextRequired
The tool to run, such as clang-tidy, llvm-mca or include-what-you-use. Choose the language first to list them.
CodesourcetextRequired
The code, as you would paste it into Compiler Explorer.
Tool argumentstool_argumentstext
Arguments for the tool. clang-tidy needs checks to run, such as -checks=bugprone-*.
Tool inputtool_inputtext
Text for tools that read input, such as a clang-query query. 'List tools' says which accept it.
Compiler flagsoptionstext
Flags for the compiler, such as -O2 -Wall -std=c++20.
Librarieslibrarieslist
Libraries the code includes, such as {fmt} or Boost. Choose the language first to list them.

Outputs

buildobject
How the build went
compilertext
The compiler ID used
diagnosticslist
Each error, warning and note, with its line
errorstext
What the tool printed to standard error
exit_codenumber
The tool's exit code
languagetext
The language ID used
outputtext
What the tool printed to standard output
summarytext
One line saying what came back
tooltext
The tool ID run
tool_nametext
The tool's name
Example output
{
  "build": {
    "diagnostics": [],
    "error_count": 0,
    "exit_code": 0,
    "stderr": "",
    "stdout": "",
    "success": true,
    "warning_count": 0
  },
  "compiler": "clang_trunk",
  "diagnostics": [
    {
      "column": 23,
      "line": 1,
      "message": "an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]",
      "severity": "warning"
    }
  ],
  "errors": "1 warning generated.",
  "exit_code": 0,
  "language": "c++",
  "output": "<source>:1:23: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]",
  "summary": "clang-tidy (trunk) exited with code 0 and reported 1 message about the code.",
  "tool": "clangtidytrunk",
  "tool_name": "clang-tidy (trunk)"
}

On this page