Live data from Hacker News

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

github.com

1–10 of 70 posts

Re: C++ Insights – See your source code with the eyes of a compiler

#2
I wonder how helpful it is for g++?

Myself and my ancient h/w and s/w engineering friends have been having a discussion recently about how the modern C++ language features are generating code that is not readily debugged at the source level.

The compiler has always created assembly that implements the feature described by teh high level language, but histoirically these have had a relatively one-to-one relationship with the source code.

However in the world of post C++11 many more abstracted features are supported, and they no longer have any kind of relation to the source in terms of something you could inspect with a debugger (except in assembly).

So it seems a tool like this is really useful, but unfortunately almost inherently compiler specific.

Maybe GNU can port this to g++?

Re: C++ Insights – See your source code with the eyes of a compiler

#3
Honestly, from the title, I expected something that gave actual 'insights' into the compiler, rather than the code. For example, indicating applied and potential (missed) optimizations. But seeing what it was, I was definitely not unpleasantly surprised :)

Being able to cut through abstraction is very nice and quite important when you want to understand WHAT you are writing from the machine's perspective (or even in general when you don't know the abstraction yet). I love using Haskell, but have no idea what kind of machine code GHC spits out at the end (something based on the spineless tagless G-machine, an abstraction I barely understand by itself).

Re: C++ Insights – See your source code with the eyes of a compiler

#4
post #2

I wonder how helpful it is for g++? Myself and my ancient h/w and s/w engineering friends have been having a discussion recently about how the modern C++ language features are generating code that is not readily debugged at the source level. The compiler has always created assembly that implements the feature described by teh high level language, but histoirically these have had a relatively one-to-one relationship w…

The readme indicates that it uses system headers (G++ libstdc++) by default.

Since it's source-to-source, I don't think being based on clang actually matters for anything unless you happen to use GCC-specific extensions. I would also expect clang and gcc to behave similary when cutting through abstraction.

I'm not sure, but it also seems like the output code should be able to compile? Then you can probably use g++ for that step.

Re: C++ Insights – See your source code with the eyes of a compiler

#5
post #2

I wonder how helpful it is for g++? Myself and my ancient h/w and s/w engineering friends have been having a discussion recently about how the modern C++ language features are generating code that is not readily debugged at the source level. The compiler has always created assembly that implements the feature described by teh high level language, but histoirically these have had a relatively one-to-one relationship w…

The readme indicates that it uses system headers (G++ libstdc++) by default. Since it's source-to-source, I don't think being based on clang actually matters for anything unless you happen to use GCC-specific extensions. I would also expect clang and gcc to behave similary when cutting through abstraction. I'm not sure, but it also seems like the output code should be able to compile? Then you can probably use g++ fo…

Most of things that used to be g++ specific extensions are in standard nowadays. You can avoid by using a more recent c++ version.

Re: C++ Insights – See your source code with the eyes of a compiler

#6
post #2

I wonder how helpful it is for g++? Myself and my ancient h/w and s/w engineering friends have been having a discussion recently about how the modern C++ language features are generating code that is not readily debugged at the source level. The compiler has always created assembly that implements the feature described by teh high level language, but histoirically these have had a relatively one-to-one relationship w…

> Myself and my ancient h/w and s/w engineering friends have been having a discussion recently about how the modern C++ language features are generating code that is not readily debugged at the source level.

What specific features do you have in mind? I generally believe this is because DWARF and debuggers haven't been keeping up, not because of inherent limitations.

Re: C++ Insights – See your source code with the eyes of a compiler

#7
C++ Insights is available online at https://cppinsights.io/

It is also available at a touch of a button within the most excellent https://godbolt.org/

along side the button that takes your code sample to https://quick-bench.com/

Those sites and https://cppreference.com/ are what I'm using constantly while coding.

I recently discovered https://whitebox.systems/ It's a local app with a $69 one-time charge. And, it only really works with "C With Classes" style functions. But, it looks promising as another productivity boost.

Re: C++ Insights – See your source code with the eyes of a compiler

#8

Honestly, from the title, I expected something that gave actual 'insights' into the compiler, rather than the code. For example, indicating applied and potential (missed) optimizations. But seeing what it was, I was definitely not unpleasantly surprised :) Being able to cut through abstraction is very nice and quite important when you want to understand WHAT you are writing from the machine's perspective (or even in…

compiler explorer/clang can do this.

https://clang.llvm.org/docs/UsersManual.html#options-to-emit...

Gcc also has similar options

Re: C++ Insights – See your source code with the eyes of a compiler

#10
post #2

I wonder how helpful it is for g++? Myself and my ancient h/w and s/w engineering friends have been having a discussion recently about how the modern C++ language features are generating code that is not readily debugged at the source level. The compiler has always created assembly that implements the feature described by teh high level language, but histoirically these have had a relatively one-to-one relationship w…

What do you mean exactly? Like the inability of putting a breakpoint on the loop condition of a range-based for loop?
Post reply on HN