answersLogoWhite

0

Functions reduce code size in one of three ways, depending on the complexity of the function.

Normally, a function call results in the compiler generating code to call and return from the function, but the code for the function itself is only generated once. This not only reduces duplication in your source code and thus makes your code much easier to read and maintain, it also reduces the overall size of the machine code if the code required to implement the call and return mechanism results in fewer operations than the function itself. However, the call and return mechanism has a runtime cost, reducing performance slightly.

Some functions can be inline expanded (by the compiler) to the extent that the expansion results in smaller code than the normal call and return mechanism would incur. By eliminating the function call mechanism, we not only improve runtime performance, we can also reduce code size.

Inline expansion does not guarantee smaller code size; in some cases we may increase the size of the code. Although increased code size can have an affect on overall performance, this has to be balanced against the performance that is gained by eliminating the function call mechanism.

Finally, some functions can take advantage of compile-time computation, which is similar to inline expansion but where complex expressions can be evaluated at compile time and thus reduced to much simpler expressions. This not only reduces code size but greatly improves performance by completely eliminating unnecessary runtime operations.

User Avatar

Wiki User

9y ago

What else can I help you with?

Continue Learning about Engineering

Why you divide a program into functions?

In order to make a large program more manageable, it is convenient to identify and isolate specific tasks that a program performs and to separate out those tasks into functions. These functions are used/invoked as needed by the main part of the program. They can also be invoked by other functions. Often a program will perform the same task in different parts of the program. Using a function to perform the task and invoking the function from the different parts of the program means that only one copy of the code is needed. This helps reduce the size of the program.


What are the advantages of microcontroller?

Microcontrollers are small in size. As such, they help in reducing the size of circuits. They are also easy to program hence presenting high levels of flexibility.


What is the principle of function generator?

with the help of function generator we found wave in oscilloscope


What is the code of a program that construct a program that displays a pyramid on the screen?

Here's a simple Python program that constructs and displays a pyramid: def print_pyramid(height): for i in range(height): print(' ' * (height - i - 1) + '*' * (2 * i + 1)) print_pyramid(5) This code defines a function print_pyramid that takes the height of the pyramid as an argument and prints a pyramid made of asterisks (*). Adjust the height parameter in the print_pyramid function call to change the size of the pyramid.


Does inline function increase the code size?

The inline specifier might increase the code size, but it might also reduce it.It depends on the size of the inlined function versus the overhead of setting up a stack frame and invoking the call/return sequence. Often, the inline specifier is used for very short, usually one line functions, and the intent is to sacrifice a bit of code size for execution size.Keep in mind that the inline specifier is only a compiler hint, and that the compiler may or may not actually inline the function, depending on context.

Related Questions

What is the importance of functions in a c plus plus program?

Functions are very important in C++, as you can't write the simplest program to print hello without using a function. Overall you can say that function are building blocks of a C++ program. Functions can also be defined by the programmer to reduce program size.


What body parts that reduce in size with no apparent function?

pineal gland


What can you do to reduce the size of an email attachment?

Zip the file with a program like WinZip.com


How POPCOM encourage people to reduce their family size?

POPCOM is a population program in the Philippines. POPCOM encourages people to reduce their family size by advocating family planning services.


How popcom encourages people reduce their family size?

POPCOM is a population program in the Philippines. POPCOM encourages people to reduce their family size by advocating family planning services.


Why you divide a program into functions?

In order to make a large program more manageable, it is convenient to identify and isolate specific tasks that a program performs and to separate out those tasks into functions. These functions are used/invoked as needed by the main part of the program. They can also be invoked by other functions. Often a program will perform the same task in different parts of the program. Using a function to perform the task and invoking the function from the different parts of the program means that only one copy of the code is needed. This helps reduce the size of the program.


What is the difference bw function pointer and function of pointer?

function pointer is a variable that hold the address of any function which declared in the program but function pointer is the array of the function that accept the run time size of the function.


Does A file compression utility is a program that removes redundancies in a file to reduce the file size?

File Compression


Would using an aerobic step help you increase the size of your butt or reduce it?

reduce it but make it round... round but small.


Will spaying a dog early help reduce the size of the dog?

no, it will make them less aggresive and help stop them running off


How do you reduce hand size for men?

When you reduce his penis size.


How can one reduce the size of their Credit Card bill?

One can reduce the size of a credit card bill by taking a number of precautions such as keeping a track on spending and costs. Other ways to help one reduce the size of the bill would be to create a budget and plan a strategy to pay off the debt.