NO

Author Topic: Code Optimization?  (Read 4548 times)

boris.kurylenko

  • Guest
Code Optimization?
« on: November 04, 2011, 04:27:57 PM »
Code: [Select]
#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

  • Guest
Re: Code Optimization?
« Reply #1 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).

boris.kurylenko

  • Guest
Re: Code Optimization?
« Reply #2 on: November 04, 2011, 04:33:00 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

  • Guest
Re: Code Optimization?
« Reply #3 on: November 04, 2011, 04:43:50 PM »
That's Odd... are you on the latest version of Pelles C? 




boris.kurylenko

  • Guest
Re: Code Optimization?
« Reply #4 on: November 04, 2011, 05:27:01 PM »
That's Odd... are you on the latest version of Pelles C?

Yes, I use version 4.50 (Release Candidate)

CommonTater

  • Guest
Re: Code Optimization?
« Reply #5 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.



« Last Edit: November 04, 2011, 06:45:42 PM by CommonTater »

boris.kurylenko

  • Guest
Re: Code Optimization?
« Reply #6 on: November 04, 2011, 07:00:09 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

  • Guest
Re: Code Optimization?
« Reply #7 on: November 04, 2011, 09:07:10 PM »
That's usually the best practice anyway... unsed code in source files == difficult maintenance later on.


Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Code Optimization?
« Reply #8 on: November 05, 2011, 05:27:39 PM »
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.

« Last Edit: November 05, 2011, 05:31:40 PM by AlexN »
best regards
 Alex ;)