You are here:

C++/error C2071 issue


I have a C file written as below:


#include "stdafx.h"

#define COMPILE_ASSERT(e) typedef char __I_BUILD_COMPILER_ASSERT_NAME(__LINE__)[(e)?1:-1]

typedef struct radeonmmregs
// Setup / Control registers
int mmIndex; // [0x0000]; MM_INDEX
int mmData; // [0x0004]; MM_DATA

int main(int argc, char* argv[])
COMPILE_ASSERT(offsetof(radeonmmregs, setup.mmIndex)== 0x0000);
return 0;


When I try to compile this code I get the following errors:

:\sss\sss2\sss2.cpp(22) : error C2071: 'COMPILER_ASSERT_AT_LINE' : illegal storage class
C:\sss\sss2\sss2.cpp(22) : error C2143: syntax error : missing ';' before '['
C:\sss\sss2\sss2.cpp(22) : error C2143: syntax error : missing ';' before '['

I cannot understand what is wrong with my code and why  occurs in Ms Visual C++ 6.0?

I need a solution to handle this error. I tried to compile with default Win32 console application project settings. I know that this code works with other compilers so I think this could be handled by changing compiler setting but I don't know how.

Any comments will be appreciated


Correction: #line is standard in C and C++ of course!

And the preprocessor should not become confused as it only recognises preprocessor tokens at the start of lines - ignoring whitespace.


Hmm, interesting. Its seems that using __LINE__ with MSVC++6 .. 7.1 (yep I started out using the latest version) is problematic in this context - it seems to loose the value or do something weird with it. I replaced __LINE__ with __COUNTER__  (an MS special I think...) and your code compiled ... after I deleted the include for stdafx.h - which leads me to think this is actually being compiled as C++.

A few points:

Using double underscores anywhere in a name is illegal for us users of the language, as such names are reserved for implementation (i.e. C/C++ implementation) use. In fact the C++ standard reserves for the implementation (any implementation) names containing double underscores and names starting with underscore followed by a capital letter for any use and names starting with an underscore for use as a name in the global namespace.

I came across one compiler that was not able to resolve the value returned from offsetof at compiler time - odd - of course this it did rather prevent using a compile time assertion in this case for this compiler.

For ideas on modern C++ compile time assertions see for example Modern C++ Design by Andrei Alexandrescu - which also mentions a variation on the C solution above.

Beware! #line is another MS special. You (and I) seem to have got away with ##line, but maybe not #line (where line is a macro parameter name)...  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2017 All rights reserved.