Microsoft KB Archive/50732

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:57, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


INFO: Pointer to Undeclared Structure Does Not Generate Error

Article ID: 50732

Article Last Modified on 7/5/2005



APPLIES TO

  • Microsoft C Professional Development System 6.0a
  • Microsoft C Professional Development System 6.0a
  • Microsoft Visual C++ 1.0 Professional Edition
  • Microsoft Visual C++ 1.5 Professional Edition
  • Microsoft Visual C++ 1.51
  • Microsoft Visual C++ 1.0 Professional Edition
  • Microsoft Visual C++ 2.0 Professional Edition
  • Microsoft Visual C++ 2.1
  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 5.0 Standard Edition
  • Microsoft Visual C++ 6.0 Service Pack 5



This article was previously published under Q50732


SUMMARY

Code that declares a pointer to a nonexistent structure compiles without warning or error. This is correct behavior.

Note that dereferencing a pointer to an undefined structure, or attempting to use a field, will produce errors. In general, you are allowed to make a reference to an undefined struct as long as the operation doesn't need to know the size of that struct or the names of its fields. This method of declaration is commonly used in linked lists.

Sample Code

   void main (void)
   {
      struct non_existent *ptr;         // legal
      struct x
      {
       struct x *previous;      // legal, note that struct x is
       struct x *next;          // not yet defined
      };
   }
                


Additional query words: 8.00

Keywords: kbinfo kbcode kbcompiler KB50732