BeeOnRope
BeeOnRope

Reputation: 65046

Can MSVC with link-time codegen optimize across C and C++?

If link-time code generation (LTCG) is being used with MSVC, is it possible that code can be optimized across the C and C++ language boundary?

For example, can a C function be inlined into a C++ caller?

Upvotes: 3

Views: 89

Answers (1)

SoronelHaetir
SoronelHaetir

Reputation: 15172

Yes, I just tried it with:

int foo() { return 5; }

in a .c file and:

extern "C" int foo();
printf("%d\r\n", foo());

in a .cpp the disassembly is:

00007FF60F6F3935  mov         edx,5  
00007FF60F6F393A  lea         rcx,[string "%d" (07FF60F727FB4h)]  
00007FF60F6F3941  call        printf (07FF60F701E00h)  

Upvotes: 3

Related Questions