Embedded C interview Questions for Embedded Systems Engineers
Contact Us For Questions, Comments or Suggestions
Q: Which is the best way to write Loops?
- Is Count Down_to_Zero Loop better than Count_Up_Loops?
A:
Q: What is loop unrolling?
A:
eg:
int countbit1(uint n)
{
int bits = 0;
while (n != 0)
{
if (n & 1) bits++;
n >>= 1;
}
return bits;
}
int countbit2(uint n)
{
int bits = 0;
while (n != 0)
{
if (n & 1) bits++;
if (n & 2) bits++;
if (n & 4) bits++;
if (n & 8) bits++;
n >>= 4;
}
return bits;
}
Q: How does, taking the address of local variable result in unoptimized code?
A:
Q: How does global variables result in unoptimized code?
A: For the same reason as above, compiler will never put the global variable into register. So its bad.
Q: So how to overcome this problem?
A: When it is necessary to take the address of variables, (for example if they are passed as a reference parameter to a function). Make a copy of the variable, and pass the address of that copy.
Q: Which is better a char, short or int type for optimization?
A:
Q: How to reduce function call overhead in ARM based systems? A:
Q: What is a pure function in ARM terminology?
A:
Pure functions are those which return a result which depends only on their arguments.
They can be thought of as mathematical functions: they always return the same result if the arguments are the same. To tell the compiler that a function is pure, use the special declaration keyword __pure.
__pure int square(int x)
{
return x * x;
}
Compiler does optimization for pure functions. For example, the values which are allocated to memory can be safely cached in registers, instead of being written to memory before a call and reloaded afterwards.
Q: What are inline functions?
A: