NO

Author Topic: Compile Optimizations  (Read 2333 times)

Offline John Z

  • Member
  • *
  • Posts: 790
Compile Optimizations
« on: January 17, 2020, 10:36:23 PM »
Using any of the compile optimizations results in numerous unreachable code warnings that are not issued when no optimization is used.  Version 9.00.9 on Windows 10
The program uses Single-threaded, _stdcall, fast FP model, Level 2 warnings, and C11 with Microsoft extensions.  WIN32 and Unicode. 

Standard Compile has no errors or warnings.

Most but not all are on WM_CLOSE
An example of the many warnings:
C:\Program Files\PellesC\Files\vCardz\vCardz\about.c(151): warning #2154: Unreachable code.
code:
             case WM_CLOSE:
warning ->>   if(hIcon) DestroyIcon(hIcon);
                        DeleteObject(hFont);
                       EndDialog(hwndDlg, 0);
            break;

An example not on WM_CLOSE - two warnings same line
C:\Program Files\PellesC\Files\vCardz\vCardz\file.c(1713): warning #2154: Unreachable code.
C:\Program Files\PellesC\Files\vCardz\vCardz\file.c(1713): warning #2154: Unreachable code.

                       if (SaveAs == FALSE)
warning ->>      { goodfile= GetOpenFileNameW(&ofn);}
                       else
                        { goodfile= GetSaveFileNameW(&ofn);}

   
Is there something I'm doing wrong?  My program is pretty straightforward and relatively
unsophisticated.  The resulting program seems to run ok, but I'd be nervous about releasing
it.....

Thanks in advance,
John

Grincheux

  • Guest
Re: Compile Optimizations
« Reply #1 on: January 19, 2020, 06:12:52 AM »
This warning is not very well explained. I met it too often for cases like yours. Very often I am obliged to rewrite my code but that does not always resolve the problem.


If Mr Pelle could give us the way to resolve that would be a good idea.

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Compile Optimizations
« Reply #2 on: January 26, 2020, 06:48:01 PM »
The basic concept of unreachable code should be self-explanatory: it's code that can't be reached/executed.
The only question is: which code is it? Your snippets doesn't help, I suspect the problem is with the surrounding code. Anyway, right now it's 99.9% guesswork.
Narrow it down to a complete, preferably small, example. Post it here with the compiler options to use, and we can take it from there...
/Pelle

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Compile Optimizations
« Reply #3 on: January 26, 2020, 10:03:26 PM »
Thanks.  Yes, 'unreachable' is self-explanatory, I did not realize/understand it involved more than what would be encapsulated within, for example, a complete If statement , or a complete Case - Break test when the 'unreachable' code line was within it.   I'll work on creating a small example and in doing so may find my error(s).

Thank you for your reply.
Regards,
John

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Compile Optimizations
« Reply #4 on: January 27, 2020, 01:22:01 AM »
Yes - indeed, I'm very sorry to have wasted your time!

The first case hicon is only set within the WM_INITDIALOG, so it needs to be static in order for it to be checkable in the message loop and to be acted upon when exiting using WM_CLOSE.

The second case was my poor code practice of putting in a future piece of code, part of which, in fact, is not currently executed because the control variable is currently fixed, until the feature is implemented, making half of the code unreachable.

So it IS me doing something wrong !  I appreciate the lesson. :-[

Regards,
John