Microsoft KB Archive/116170

= FIX: C2099 Generated Initializing Struct with Macro =

Article ID: 116170

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft C/C++ Professional Development System 7.0
 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 1.5 Professional Edition
 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 4.1 Subscription
 * Microsoft Visual C++ 4.2 Professional Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 5.0 Learning Edition

-



This article was previously published under Q116170



SYMPTOMS
Using a macro to initialize a structure causes the C/C++ compiler to incorrectly generate the following error message:

error C2099: initializer is not a constant



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft Visual C++ version 6.0.



MORE INFORMATION
The sample code below can be used to reproduce this problem:

Sample Code
/* Compile options needed: none */

#include 

#define ZIP    struct zip_struct #define ZOT    struct zot_struct #define TABLE  struct table_struct

ZIP {     ZOT {        int num; } m_zot; };

#define MACRO(tok) \ { (offsetof(ZIP, m_zot.tok) - offsetof(ZIP, m_zot)) / sizeof(int) }

TABLE {     int Offset; int ModNum; };

TABLE test[] = { { offsetof(ZIP, m_zot.num) - offsetof(ZIP, m_zot) / sizeof(int) } }; TABLE test2[] = { { MACRO(num) } };

void main(void) {  }

Additional query words: kbVC400bug 8.00 8.00c 9.00 10.00 10.10 10.20

Keywords: kbbug kbfix kbvc600fix KB116170

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.