3

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?

BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
  • Motivated by https://stackoverflow.com/a/48030595/841108 – Basile Starynkevitch Dec 30 '17 at 04:04
  • 2
    I'm not comfortable with 4 very closely related questions being asked in a matter of minutes. (The complete set, including this, are: https://stackoverflow.com/questions/48030795/, https://stackoverflow.com/questions/48030786/, https://stackoverflow.com/questions/48030706/, https://stackoverflow.com/questions/48030818/). I can't help but feel that a single question about which of the 4 compilers can do it would be better. It feels like a 'rep grubbing' ploy. Maybe that's harsh, but… – Jonathan Leffler Dec 30 '17 at 04:21

1 Answers1

3

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)  
SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23