Reputation: 5462
I wonder if it would be possible to effectively use link-time optimization (lto) for programms consisting of a TU with C++ code calling some function in a TU with C code. So, is there a way to get the C function inlined into the resulting program?
The real use case is a microcontroller firmware written in C++. But there are pieces of code that have to written in C because of C semantics (e.g. access to the non-active union member).
(This has nothing to do with manual marking functions as inline)
Upvotes: 1
Views: 495
Reputation: 356
This should not be a problem at all. In both GCC and Clang link-time optimization operates on intermediate representation of the code. That is, by using -flto
you create object files with additional LTO information (gcc) or LLVM bytecode (Clang), at which point the source language stops to matter.
Some go as far as to mix even less related C++ and D yet still use LTO: http://johanengelen.github.io/ldc/2016/11/10/Link-Time-Optimization-LDC.html
Upvotes: 4