logoalt Hacker News

C++ Insights – See your source code with the eyes of a Compiler

127 points • by rramadass • last Thursday at 11:53 PM • 26 comments • view on HN

Comments

alankarmisra • today at 2:28 PM

Ooo I love these things. I wrote a C++ -> Clang -> JS transpiler so I could show value change states on top of the C++ source code in html and allow people to step through the whole state change. They can also vary the input and see the values change cause the JS layer could recompute the values - which is why I bothered with the transpiling - otherwise I could have just output the state changes and parsed them as CSV for the steps. Fun project!

https://youtu.be/ZPGysUX62OY

jsrcout • today at 4:10 PM

Definitely trying this out. I've always had the problem of "but what is the compiler thinking?" with C++ in particular.

kvemkon • today at 9:07 PM

> See your source code ...

What I'd like to see, is how much time is spent to compile each block of C++ code (sliced as fine as possible).

StilesCrisis • today at 2:00 PM

I wish the readme example showed a lambda capture. Now that's where compiler magic REALLY shows up.

➕ show 5 replies
f1shy • today at 4:21 PM

I must be the only one who (while I like the tool) feel a little strange, somewhere between sad, angry, annoyed and disappointed (can’t really express it), that a language needs (or at least is of good use) such a tool.

Like: I wish what is the first interpretation of my code to be obvious. Is not about advanced optimization, or nitty gritty compiler tricks, is about the language. This tool is useful in any C++ compiler. How did we end with such a complex language?

I mean (sorry, very personal take) the programming language is for me a tool to help me think about a problem and its solution. In this era of LLM more than before, is not a tool to get the machine to do something, is a language for formalizing ideas, problems and solutions, like math. Should not be so obscure, that you need to be a lawyer to understand it, right? Or I am very much old and totally in the weeds with my ideas?

➕ show 4 replies
rramadass • last Thursday at 11:53 PM

The tool can be found at - https://cppinsights.io/

IshKebab • today at 4:11 PM

This is what let me understand lambdas. Great tool.

➕ show 1 reply
tweedler290 • today at 5:59 PM

thats crazy. i made this https://github.com/oooscoos/Benzi which does the same thing but is language agnostic (supports 9 other languages). urs probs goes in deeper into c++ than mine tho

➕ show 1 reply