Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c

visual-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?

like image 391
BeeOnRope Avatar asked Jan 29 '26 17:01

BeeOnRope


1 Answers

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)  
like image 69
SoronelHaetir Avatar answered Jan 31 '26 05:01

SoronelHaetir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!