FIX: C++ Compiler Hangs Calling new() For Unknown Class
PSS ID Number: Q115532
Article last modified on 07-14-1994

7.00

MS-DOS


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

 - Microsoft C/C++ Compiler for MS-DOS, version 7.0
----------------------------------------------------------------------

SYMPTOMS
========

Allocating memory for a class object using new() may cause the compiler to
hang if the class type is undefined. In this case, the compiler hangs after
displaying the following error message:

      test.cpp(90) : error C2061: syntax error : identifier 'node'

The source code shown below, in the "MORE INFORMATION" section, can be used
to illustrate this problem.

RESOLUTION
==========

The compiler does correctly identify the error before hanging; therefore,
fixing the error keeps the compiler from hanging because of calling new()
for an undefined class.

STATUS
======

Microsoft has confirmed this to be a problem with the C/C++ compiler,
version 7.0. The problem was corrected in the C/C++ compiler, version 8.0,
supplied with Visual C++ for Windows, version 1.0.

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

The following sample code can be used to demonstrate this problem:

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

/* Compile options needed: /c
*/
      class My_Node
      {
         int  length;

       public:
         My_Node();
        ~My_Node() {}
      };

      My_Node::My_Node()
      {
         length = 0;
      }

      class Sequence
      {
         My_Node *first;
         int seq_condition;
       public:
         Sequence() { seq_condition = 0; }
         ~Sequence();
         void insert_front(void *c);
      };

      Sequence::~Sequence()
      {
         delete first;
      }

      void Sequence::insert_front(void * c)
      {
         My_Node *temp;

         seq_condition = 0;

         if(!first)
         {
            if(!first = new node(c))   // error C2061
               seq_condition = 1;
         }
         else
         {
            if(!(temp = new node(c))   // error C2061
            {
               seq_condition = 1;
               return;
            }
            first = temp;
         }
      }

Additional reference words: 7.00
KBCategory: Tls
KBSubCategory: CPPIss

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

Copyright Microsoft Corporation 1994.
