TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Gary Chambers
from: Mike Bilow
date: 1996-02-09 10:12:28
subject: Code has no effect...

Gary Chambers wrote in a message to Mike Bilow:

 GC> "Code has no effect in function xxx"

 MB> On which line is the warning reported?

 GC> It's being reported on each WinCheckMenuItem(...) line.  If
 GC> they're removed, the warnings cease.  I was initally call
 GC> WinSendMessage(..., MM_SETITEMATTR, ...) until I stumbled
 GC> across the predefined macro in one of my references. 

 MB> Is mp1, by any change, already an unsigned short?

 GC> No.  It's coming straight out as an MPARAM.

The macros are:

   #define MIA_CHECKED                0x2000

   typedef VOID *MPARAM;
   #define MAKEULONG(l, h)  \
      ((ULONG)(((USHORT)(l)) | ((ULONG)((USHORT)(h))) << 16))
   #define MAKELONG(l, h)   ((LONG)MAKEULONG(l, h))
   #define MPFROM2SHORT(s1, s2)       ((MPARAM)MAKELONG(s1, s2))

   #define LOUSHORT(l)     ((USHORT)((ULONG)l))

/***************************************************************************
   * BOOL WinCheckMenuItem(HWND hwndMenu, ULONG/USHORT id, BOOL fcheck)
   *    Sets the check state of menuitem #id to fcheck.
   *    returns fSuccess.
***************************************************************************/
   #define WinCheckMenuItem(hwndMenu, id, fcheck) \
   ((BOOL)WinSendMsg(hwndMenu, MM_SETITEMATTR, \
   MPFROM2SHORT(id, TRUE), \
   MPFROM2SHORT(MIA_CHECKED, (USHORT)(fcheck) ? MIA_CHECKED : 0)))

Your two lines of code are:

   WinCheckMenuItem(hwndMenu, usMeasure, FALSE);         /* A */
   WinCheckMenuItem(hwndMenu, LOUSHORT(mp1), TRUE);      /* B */

Expanding MPFROM2SHORT results in:

   (VOID *)((LONG)((ULONG)(((USHORT)(s1)) | ((ULONG)((USHORT)(s2))) << 16)))

Expanding the macros yields:

   ((BOOL)WinSendMsg(hwndMenu, MM_SETITEMATTR,
      (VOID *)((LONG)((ULONG)(((USHORT)(usMeasure))
            | ((ULONG)((USHORT)(1))) << 16))),
      (VOID *)((LONG)((ULONG)(((USHORT)(0x2000))
         | ((ULONG)((USHORT)((USHORT)(0) ? 0x2000 : 0))) << 16))));

   ((BOOL)WinSendMsg(hwndMenu, MM_SETITEMATTR,
      (VOID *)((LONG)((ULONG)(((USHORT)(((USHORT)((ULONG)mp1))))
            | ((ULONG)((USHORT)(1))) << 16))),
      (VOID *)((LONG)((ULONG)(((USHORT)(0x2000))
         | ((ULONG)((USHORT)((USHORT)(1) ? 0x2000 : 0))) << 16))));

Now, although this is a pretty dense mess, I think you can see that there
is very obvious code which has no effect as a result of the macro
expansion.  In particular, you are testing a constant in each case and
applying the ternary operator on the basis of its value:

   ((ULONG)(0 ? 0x2000 : 0)) << 16
   ((ULONG)(1 ? 0x2000 : 0)) << 16

This is a construct that you would never write by hand, and it is perfectly
resolvable at compile time.  As a result, the compiler warns you about it.
 
-- Mike


--- 
* Origin: N1BEE BBS +1 401 944 8498 V.34/V.FC/V.32bis/HST16.8 (1:323/107)
SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 323/107 170/400 396/1 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.