NO

Author Topic: big trouble with optimizing  (Read 3137 times)

whatsup

  • Guest
big trouble with optimizing
« on: September 03, 2010, 11:03:15 AM »
first of all, the main reason i'm using pelles is because of the optimization.

i have a project (attached)
that i'm facing big trouble.
when i build it with optimization turned off, everything works fine.
when i build it with optimization turned on, there is a bug.

the bug is that the list in the second column , doesn't exist.

i tried to produce asm code, but couldn't find the problem.
i'll appreciate if someone can solve this mistory.

thanks in advanced.

in the attached file, you'll find the c file, and the batch i use to build it.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: big trouble with optimizing
« Reply #1 on: September 03, 2010, 01:33:11 PM »
It's simply a problem of LV_ITEM structure initialization.
By zeroing that structure before to use (that should be a good practice always, especially if you don't fill in all the fields) the problem is corrected.
It apparently seems to depend on optimizations because for some reason the rubbish on the stack assigned to the automatic variable is correct or not (depending on the stack former usage) based on optimization.
Make the following change and it will work for any optimization. Alternatively you can set the remaining structure members (like mask, stateMask, etc.) with correct values.

Code: [Select]
void MakeListView (HWND hWnd)
{
  LV_COLUMN  lvCol;
  LV_ITEM  lvItem;
  memset(&lvItem,0,sizeof(LV_ITEM)); //Set unused members to zero
« Last Edit: September 03, 2010, 01:39:24 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

whatsup

  • Guest
Re: big trouble with optimizing
« Reply #2 on: September 05, 2010, 02:04:16 AM »
thank you so much sir.
i'm shame it was my fault :(

CommonTater

  • Guest
Re: big trouble with optimizing
« Reply #3 on: September 05, 2010, 05:58:00 PM »
It's simply a problem of LV_ITEM structure initialization.
Code: [Select]
void MakeListView (HWND hWnd)
{
  LV_COLUMN  lvCol;
  LV_ITEM  lvItem;
  memset(&lvItem,0,sizeof(LV_ITEM)); //Set unused members to zero

Pelles C will also "auto initialize" the struct for you...

LV_ITEM lvitem = {0};

Will cause the compiler to generate the initialization code for you.