Im having a problem trying to fix the compiling options. I need to make it so both FunctionOne and FunctionTwo have 2 seperate Ends. But for some reason the compiler combines both of them causing major errors in my app : (
FunctionOneEnd and FunctionTwoEnd both don't do anything. Your compiler probably just generates a single instruction that just pops the instruction pointer for both functions when there's nothing in them. This isn't an error- the behavior would be the same either way. This can not cause any errors in your application unless you depend on certain side effects to occur that have nothing to do with what you actually wrote in your code.
If you just need FunctionOneEnd and FunctionTwoEnd so you can find where FunctionOne and FunctionTwo end, you could change them so they do slightly different things.
void FunctionOne()
{
for(short i = 10; i >= 0; i--)
cout << "Number: " << i << endl;
}
int FunctionOneEnd()
{
return 1;
}
void FunctionTwo()
{
for(short i = 0; i <= 10; i++)
cout << "Number: " << i << endl;
}
int FunctionTwoEnd()
{
return 2;
}
Andy
P.S. I am intrigued why you want to do this. Note that in the optimized build, the smaller functions are often inlined. So this technique will not be appropriate in this case.
Damn, im trying to do this because im attempting to get the size of FunctionOne and FunctionTwo while trying to make my application very small (adding random code that wont do anything is blah)
As your FunctionTwoOne() and FunctionTwoEnd() do nothing, I would expect the optimizer to strip them out. I presume this isn't happening as you're taking their addresses.
Yes that is correct all im doing to find the size is subtracting FunctionOneEnd to FunctionOne. Is there a compiler setting i can turn off to remove this feature?
Why do you need the 'End functions in the final release? I thought you were using them to help you optimise your code. But once your done, you could remove them for the final version.
Also, by taking the addresses of your functions, I believe you will disrupt the compilers inlining mechanism. It can't inline a function that has to have a distinct address. So you could actually be making your code bigger.
And linkers can be told to do function level linking and whole program optimization. When these are used I'm not even sure if the order of functions in the binary is guaranteed to be the same as that in the source file(s).
But while your experimenting, why can't FunctionTwo act as the "End" for FunctionOne, etc. Then you just need one "Last" function.
You are attempting completely ad hoc optimizations here. If you care for size, just tell your compiler to optimize for size, and don't do stuff that wastes too much space.
Oh, well im trying to get the size of functions without making unique "ends". Increasing the file size a little with FunctionOneEnd() {} rather than a unique one for each "end".
@Andy: I will see what I can do because sometimes the order of which every function is placed can effect the out come of the function size.