Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replacing all function calls with their definition in a C/C++ code

I wonder if there is some theory/tool available to replace a piece of code that contains function calls, into code where all function call has been replaced by their respective code.

like

main()
{
   fun();
}

fun()
{
   int i;
   fun2();
}

fun2()
{
   int j;
}

into

main()
{
   int i;
   int j;
}

I know there is a lot to take care of, like local variable names, recursive calls, external function calls etc etc. .. ..

I also know that it may not be at all useful, but still does something like this exist? even in theory?

should I call it advance per-processor unit :)

like image 639
Amar Avatar asked Nov 30 '25 04:11

Amar


1 Answers

The compiler can usually tell when it's a good idea to do this, and already automatically does inlining whenever needed. You can also suggest that a function should be inlined using the inline keyword before a function (note that it still doesn't actually force it, and the compiler might decide to avoid the inlining).It's generally not such a good idea to do this manually, as modern compilers tend to figure out the best possible inlinings on their own. This article explains inline functions really well, I found it very helpful

Edit 1:

There are several reasons why one might want to do that inlining you speak of. If you feel like your code is divided into many different functions reducing its clarity and making it overly verbose, you could try a refactoring tool, such as the one provided by the VAssist X Visual Studio plugin. Though this plugin doesn't really do what you suggest (I can't think of a tool that does), it can help move functions/ methods around with ease, allowing you to clean up your code.

like image 95
Andrei Bârsan Avatar answered Dec 01 '25 20:12

Andrei Bârsan



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!