KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q50212: C2205: Cannot Initialize Extern Block-Scoped Variables

Article: Q50212
Product(s): See article
Version(s): 2.00 2.01
Operating System(s): MS-DOS
Keyword(s): ENDUSER | S_C S_QuickASM | mspl13_c
Last Modified: 6-NOV-1989

The error message "C2205 : <filename> : cannot initialize extern
block-scoped variables" occurs when compiling a submodule that both
declares and initializes an external global variable on the same
statement line. This error is caused by the incorrect placement of a
declaration.

The following are two suggestions for proper declaration:

1. The external declarations should be outside the submodule file
   scope (for example, move the declaration from the local area to the
   global area).

2. Declare the external variable on one line, then initialize it on
   the next statement.

The following program illustrates the compiler error when compiled
with the C 5.10 optimizing compiler or QuickC Version 2.01.

Program Sample
--------------

#include <stdio.h>

int  n;                  /* global variable */
void submodule (void);   /* routine in separate .OBJ file */

void main (void)
{
   submodule ();
   printf ("n = %d", n);
}

void submodule (void)
{
   extern int n = 10;
}

Applying the two suggestions for proper declaration results in the
following:

1.
      extern int n = 10;

      void submodule (void)
      {
      }

2.

      void submodule (void)
      {
      extern int n;
      n = 10;
      }

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.