Question

Does anyone know if it is possible to enable any kind of logging on any C++ compliant compiler (Visual Studios, g++ etc) so that I can discover when temporary objects are created?

For example:

Let's say I have a function f(char x) but I call this with f(46)

I will see in the logs -

temporary char created promoting int @ function param f(46) (or something like this)

I have read through the VS compiler switch options and it appears that this is not an option.

I understand that in the new standard there is the concept of an rvalue reference (&&) which could be used to detect most temporaries for the move semantics but this involves adding new code / compliant compiler.

So can this be done? Or is this privileged knowledge of the compiler?

Was it helpful?

Solution

What would be more useful would be inline annotations in the IDE (since I assume you want to optimise by minimising some of these temps?). In practice the easiest way would be to modify GCC or g++ and make them talk to a Visual Studio plugin or something. They could annotate with the register allocation and everything. Wow, that would actually be really helpful.

Barring an effort like that, and I don't know of any, the best way is to just learn to read the assembly. In Visual Studio you can have the compiled assembly appear inline with the source which is super useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top