C ++: built-in functions and timecode code generation

Until some time ago, my code base was very close to #include hell. Every time I even changed a slightly important .h file, almost all the files were recompiled.
The main reason for such a high dependence of the header was that I have many small functions that should be built-in, and I had the impression that for working inside they should be in the same translation system as the call code, therefore they should be in the title. For a built-in function to compile other headers, you must also include ad infimum in the header.

Enter the connection time code generation (in Visual Studio). One of the main claimed benefits of this is that the built-in function can now cross over translation units. But I will still. How can I really be sure that these features are really built-in? I understand that, in principle, the compiler can do whatever it wants, no matter where I define the function.

Is there any way to check what happens?

+7
c ++ visual-studio header inline
source share
5 answers

I know this is taboo in C ++ to say it, but you can implement these functions as preprocessor macros. Excuse me while I wash my mouth with soap.

+7
source share

Surely you don't care if things get up - you don't care if the performance is satisfactory. But if you really want to find out, check out the code that the compiler generates. You can do this most easily through the debugger using the assembler viewport.

+3
source share

You can never be sure that features are built-in. It is up to the compiler to select this. But you can make it easier for the compiler by letting it find the object code associated with this function.

This is where the time code generation comes from. Compilers no longer generate object code, they generate an intermediate language form and this is the linker that actually compiles the code.

To check what is included, I'm afraid that you will leave the assembly production along with your object code. This allows you to read the exact object code created by calling a particular function, and it will be very clear if there is a β€œcall” there.

+3
source share

One relatively simple way is to use a profiler. If the function is enabled, you will not see it in the flow of the control chart.

+3
source share

Once you have the executable, you can use the tools to check it and look for the names of the built-in functions in the symbol tables. One such useful tool is the Dependency Walker .

This, of course, suggests that you can get an assembly that combines both sufficient optimization options and a compiler to support nesting while preserving characters.

For Visual Studio, I think Release builds often match these, but I'm not quite sure.

+1
source share

All Articles