PRB: /Ot and Shift Operator Code Generation Inconsistencies
PSS ID Number: Q104635
Article last modified on 12-21-1993

5.10 6.00 6.00a 6.00ax 7.00 7.00a

MS-DOS


----------------------------------------------------------------------
The information in this article applies to:

 - Microsoft C Compiler for MS-DOS, versions 5.1 6.0, 6.0a, and 6.0ax
 - Microsoft C/C++ Compiler for MS-DOS, versions 7.0 and 7.0a
----------------------------------------------------------------------

SYMPTOMS
========

The Microsoft C compiler, under certain circumstances, generates code
differently for shifted longs. If the /Ot (optimize for time) switch
is used and the source and destination of the long to be shifted are
the same, then inline code is not generated. However, if the source
and destination of the long value to be shifted are different, then
inline code is generated.

STATUS
======

Microsoft has confirmed this to be a problem in C versions 5.1, 6.0,
6.0a, and 6.0ax, and in C/C++ 7.0 and 7.0a. This problem was corrected
in Microsoft Visual C++ for Windows, version 1.0.

MORE INFORMATION
================

When the sample code listed below is compiled with the /Ot switch,
only shift line 3 has inline code generated for it. The other two
shift lines have function calls in their assembler code.

Sample Code
-----------

/* Compile options needed: /Ot /Fc
*/

void do_nothing (unsigned long *arg)
{
  *arg = *arg;
}

void main (void)
{
  unsigned long a = 1,
                b = 1,
                c = 1,
                d = 1;

  do_nothing(&a);
  do_nothing(&b);
  do_nothing(&c);
  do_nothing(&d);

  a = a >> 15;  // Shift line 1
  b >>= 15;     // Shift line 2
  c = d >> 15;     // Shift line 3: source and dest different
}

Additional reference words: 5.10 6.00 6.00a 6.00ax 7.00 7.00a
KBCategory: APrg
KBSubcategory:

=============================================================================

Copyright Microsoft Corporation 1993.
