Questions tagged [compiler-explorer]

Compiler Explorer, sometimes referred to as godbolt.org, is an interactive compiler exploration website. It allows the user to enter code in one of the supported languages, select a compiler and view the resulting assembly. Optionally, Compiler Explorer can also execute the code and show the output. Use this tag for questions regarding the use and results of Compiler Explorer, and not simply because a code snippet is hosted there.

Compiler Explorer is an interactive compiler exploration website. Edit code in C, C++, Rust, Go, D, Haskell, Swift, Pascal, ispc, Python, Java or in any of the other 31 supported languages, and see how that code looks after being compiled in real time. Multiple compilers are supported for each language, many different tools and visualisations are available, and the UI layout is configurable (thanks to GoldenLayout).

Try out at godbolt.org, or run your own local instance.

Compiler Explorer follows a Code of Conduct which aims to foster an open and welcoming environment.

Compiler Explorer was started in 2012 to show how C++ constructs translated to assembly code. It started out as a tmux session with vi running in one pane and watch gcc -S foo.cc -o - running in the other.

Since then, it has become a public website serving around 2,250,000 compilations per week.

Source: Compiler Explorer on GitHub

39 questions
16
votes
3 answers

How to generate godbolt like clean assembly locally?

I want to generate clean assembly like Compiler Explorer locally. Note that, I read How to remove “noise” from GCC/clang assembly output? before attempting this. The output using that method isn't as clean or dense compared to godbolt and still has…
Waqar
  • 8,558
  • 4
  • 35
  • 43
13
votes
1 answer

Why does the MSVC C++ compiler expand a simple Hello World into 4000 lines of assembly?

Lately I'm diving into optimizing my C++ code and as such started to play around with the compiler explorer. Since i am mainly developing on windows with Visual Studio i used the msvc compiler. At some point msvc got out of hand. after some…
Flowly
  • 215
  • 1
  • 2
  • 8
13
votes
1 answer

How to test C++ modules with godbolt (compiler explorer)?

In order to ask questions about or demonstrate bugs/features with self-written modules in C++20, it would be great to be able to use Matt Godbolt's compiler explorer. Example: test.cpp (module test): export module test; export template
Rumburak
  • 3,416
  • 16
  • 27
10
votes
1 answer

Godbolt does not show stdout

I am using https://godbolt.org/ to compile a simple C++ script but even the simplest int main() { std::cout << "Hello World!" << std::endl; } When I click Add new... --> Compiler --> Output I get: Compiler returned: 0
Hector Esteban
  • 1,011
  • 1
  • 14
  • 29
9
votes
1 answer

Step into standard library call with godbolt

I want to know how various compilers implement std::random_device, so I popped it into godbolt. Unfortunately, the only thing it says is std::random_device::operator()(): push rbp mov rbp, rsp sub rsp, 16 …
user14717
  • 4,757
  • 2
  • 44
  • 68
8
votes
1 answer

high performance 'proper' c++ alternative to variable length array

I am writing a function which requires an array to be created at runtime. The array will be of small size so I am not worried about unsafe code, however, I want to write 'proper' code. As such I am considering three alternatives: char…
Ebony Ayers
  • 350
  • 1
  • 3
  • 9
7
votes
2 answers

#include of a HTTP URL in C++

I was looking at a random C++ example on Github ( https://github.com/Quuxplusone/coro/blob/master/examples/pythagorean_triples_generator.cpp ), and was surprised to see that it actually compiles ( https://coro.godbolt.org/z/JXTX4Y ). #include…
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
5
votes
1 answer

unique_ptr not generating delete instruction in Compiler Explorer?

I've been playing around with the Compiler Explorer recently. I loaded one of their examples that takes pointer parameters and changed it to instead take unique_ptr parameters. But I noticed that in the output assembly, calls to operator delete were…
Jeff M
  • 2,492
  • 3
  • 22
  • 38
4
votes
2 answers

Chained coroutine task example segfaults

In "C++20 - The Complete Guide", Josuttis uses the following code to show how making a coroutine implement the interface of an awaiter makes it possible for it to store sub-coroutines that are resumed automatically when the outer coroutine is…
Enlico
  • 23,259
  • 6
  • 48
  • 102
4
votes
1 answer

Why is Visual Studio on Compiler Explorer ignoring the Exception Model setting?

When I try to use the /EHs flag in a Compiler Explorer testcase (to "enable" exceptions passing through extern "C" functions), VC++ 19.22 seems to be ignoring it, based on it still kicking out a C5039 and not actually changing the code. What am I…
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
3
votes
1 answer

Why does "std::cout << char() << std::endl;" not even print a new line on Compiler Explorer?

This code: #include int main() { std::cout << "---" << std::endl; std::cout << char() << std::endl; std::cout << "---" << std::endl; } prints this: --- --- Why isn't std::endl causing a new line to be between the other…
Enlico
  • 23,259
  • 6
  • 48
  • 102
3
votes
0 answers

(How) can I build multi-file projects on Compiler Explorer with MSVC?

This is the link that Matt Godbolt posted on reddit a year ago or so: a multifile project compliled by his Compiler Explorer. Clearly, as soon as I change the compiler to MSVC, the building fails; not just because of the options (e.g. -std=c++17…
Enlico
  • 23,259
  • 6
  • 48
  • 102
3
votes
1 answer

How to use in GCC trunk?

From https://github.com/gcc-mirror/gcc/commit/3acb929cc0beb79e6f4005eb22ee88b45e1cbc1d commit, C++ standard header exists things such as std::stacktrace_entry but is not declared since _GLIBCXX_HAVE_STACKTRACE is not defined neither. I…
Desmond Gold
  • 1,517
  • 1
  • 7
  • 19
3
votes
0 answers

Compiler explorer allows multiple editors. Can the contents of one editor be #included in another editor?

Godbolt's Compiler Explorer allows the creation of additional editors. Can the body of one editor be #included in another? Something similar to this? https://godbolt.org/z/vvzE9jrzq Obviously this doesn't work, but is there a way to make this…
iwans
  • 445
  • 3
  • 13
3
votes
1 answer

ranges::subrange in MSVC on Compiler Explorer

The following code compiles and runs just fine with GCC 8.3 and with Clang 10.0.1, whereas it fails miserably on MicroSoft shiny compiler. #include #include int main(){ std::vector
Enlico
  • 23,259
  • 6
  • 48
  • 102
1
2 3