DCSIMG
Visual C++ Compiler ERROR C2016 - Asaf Shelly

Visual C++ Compiler ERROR C2016

Published Tuesday, December 29, 2009 5:58 PM

Compiling a C file with Visual Studio 2008 compiler I got this error:

"error C2016: C requires that a struct or union has at least one member"

I am writing this post because it is not documented, and C2016 on MSDN is defined as "A newline character was found before the closing single quotation mark of a character constant". Either it is not well documented or I don't know where to look for it. Whatever the reason I can only guess that someone else will find the same problem.

This is the cause:

struct
{
   int    u8Type;
   int    u8LenExtended;
   int   u16Length;
} Base_Request;

struct Request_Ex
{
   Base_Request Request;
   int Address;
   int Length;
};

This is the fix:

typedef struct
{
   int    u8Type;
   int    u8LenExtended;
   int   u16Length;
} Base_Request;

struct Request_Ex
{
   Base_Request Request;
   int Address;
   int Length;
};

This is over simplified intentionally.

Asaf

תגים:,

Comments

# Frank said on Wednesday, December 30, 2009 4:11 AM

struct Base_Request

{

  int    u8Type;

  int    u8LenExtended;

  int   u16Length;

} ; // struct Base_Request

# AsafShelly said on Wednesday, December 30, 2009 10:04 AM

Adding a file called temp.c (not cpp) I still get the same error c2016 for this:

struct Base_Request

{

 int    u8Type;

 int    u8LenExtended;

 int   u16Length;

} ; // struct Base_Request

struct Request_Ex

{

  Base_Request Request;

  int Address;

  int Length;

};

# Visual C++ Compiler ERROR C2016 « Jasper Blog said on Wednesday, December 30, 2009 11:06 AM

Pingback from  Visual C++ Compiler ERROR C2016 « Jasper Blog

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: