big trouble with optimizing

Started by whatsup, September 03, 2010, 11:03:15 AM

Previous topic - Next topic

whatsup

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.

frankie

#1
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.

void MakeListView (HWND hWnd)
{
  LV_COLUMN  lvCol;
  LV_ITEM  lvItem;
  memset(&lvItem,0,sizeof(LV_ITEM)); //Set unused members to zero
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

whatsup

thank you so much sir.
i'm shame it was my fault :(

CommonTater

Quote from: frankie on September 03, 2010, 01:33:11 PM
It's simply a problem of LV_ITEM structure initialization.
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.