You are here:

C++/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 error C2071 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

I don't think this would compile in any compiler, as the format of defining COMPILE_ASSERT is wrong. You never used the parameter 'e' in its declaration!
Also I wonder why you define typedef is that manner and inside the main function. The logic of this code is very confusing.


All Answers

Answers by Expert:

Ask Experts




You may ask me about simple to complicated C/C++ programming methods/style and most like questions about network programming in C++.


I'm a professional programer in C++ and network/internet programming.

©2016 All rights reserved.