Code Optimization?

Started by boris.kurylenko, November 04, 2011, 04:27:57 PM

Previous topic - Next topic

boris.kurylenko

#include <windows.h>

void foo()
{
MessageBoxW(NULL, L"foo", NULL, 0);
}

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
return 0;
}


I have my code as shown in the above snippet, after I compile and link the foo function that is unused is still there as well as its associated imports. I do not see an option in the compiler/linker settings to remove unused code...

Any experienced users have some advice for me? Thank you.

CommonTater

I don't generally have unused code in my source :D  but I believe the Compiler's Minimize Size setting does remove dead code...

Project -> Project Options -> Compiler -> Optimization -> Minimize Size (More).

boris.kurylenko

Quote from: CommonTater on November 04, 2011, 04:31:20 PM
I don't generally have unused code in my source :D  but I believe the Compiler's Minimize Size setting does remove dead code...

Project -> Project Options -> Compiler -> Optimization -> Minimize Size (More).

I have tried this, and still the function is in the output binary.

CommonTater

That's Odd... are you on the latest version of Pelles C? 




boris.kurylenko

Quote from: CommonTater on November 04, 2011, 04:43:50 PM
That's Odd... are you on the latest version of Pelles C?

Yes, I use version 4.50 (Release Candidate)

CommonTater

#5
Ummm... I assume you meant 6.50 rc4? 

( If not then you can get updated HERE )

If you can demonstrate the issue with the latest version, you might consider submitting it as a bug report or feature request in the appropriate forum.  Although Pelles C works on the object level, that is if you compile an obj file with multiple functions in it, they all get linked in even if the functions are not used.  So I don't know if this is actually a bug or just the nature of the beast.




boris.kurylenko

Quote from: CommonTater on November 04, 2011, 06:43:02 PM
Ummm... I assume you meant 6.50 rc4? 

( If not then you can get updated HERE )

If you can demonstrate the issue with the latest version, you might consider submitting it as a bug report or feature request in the appropriate forum.  Although Pelles C works on the object level, that is if you compile an obj file with multiple functions in it, they all get linked in even if the functions are not used.  So I don't know if this is actually a bug or just the nature of the beast.

I think I understand, the entire Object File gets linked even if the functions are not used. I will just make sure I do not have code That I do not use in my source files.

CommonTater

That's usually the best practice anyway... unsed code in source files == difficult maintenance later on.


AlexN

#8
This kind of unused code can't be removed from the compiler. The only one, who can remove unused functions is the linker and AFAIK there are only few linkers, which can remove a functions.

The code which you see as unused can be necessary for a library which you link to your code.

best regards
Alex ;)