C++ anonymous struct unusual definition

113 views Asked by At

Looking at some .h script I saw this:

struct
{
  int resource;
} SimulRes[SIMULRES];

Where SIMULRES is define above as:

#define SIMULRES 50

I assume this is an anonymous struct but I am used to seeing it defined inside a named struct instead. How does this behave with different c++ compilers? What does parameter inside square brackets do? Thanks.

2

There are 2 answers

0
SergeyA On

This is not C++ syntax, but a C syntax.

It merely means defining an array SimulRes, of 50 (SIMULRES) elements, where type of the elements is a struct having a single item resource.

0
dbush On

This definition creates an array of size SIMULRES of an anonymous struct.

Because the struct type is anonymous, you can't pass it to a function or create any other instances (or pointers) other that the one that has already been defined.