You are here:

C++/C2071 issue

Advertisement


Question
hi,
I have a C file written as below:

-----------------------------------------------


#include "stdafx.h"
#define __I_BUILD_COMPILER_ASSERT_NAME__(line)  COMPILER_ASSERT_AT_LINE##line
#define __I_BUILD_COMPILER_ASSERT_NAME(line)    __I_BUILD_COMPILER_ASSERT_NAME__(line)

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

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

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
Regards,
Cem  

Answer
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.

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Sam

Expertise

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

Experience

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

©2016 About.com. All rights reserved.