4

The code snippet:

static struct
{
     static const unsigned char myConstArray[] =
     {
           50, 51, 52, 52, 53, 54, 55, 55, 56, 57, 58, 58, 59, 60,
     };

     //more....
 }_SomeValues;

How could this work? (complains that after = a ; is missing)

1
  • Plain C can't have static members in a struct. Commented Oct 23, 2012 at 14:36

3 Answers 3

8

Change to:

static struct
{
     const unsigned char myConstArray[14];

} _SomeValues =
    {
        {
           50, 51, 52, 52, 53, 54, 55, 55, 56, 57, 58, 58, 59, 60,
        }
    };
Sign up to request clarification or add additional context in comments.

1 Comment

the real one is a bit bigger: {{{0,0,0,0,0},{0,0,0,0}},{0,0,0,0,0},{0,0,0,0}},0,{0,0},{50, 51, 52, 52, 53, 54, 55, 55, 56, 57, 58, 58, 59, 60, 61, 62, 63, 64, 65, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 98, 99, 100, 102, 103, 105, 106, 108, 109, 111, 112, 114, 115, 117, 118, 120, 122, 123, 125, 127, 129, 130, 132, 134, 136, 137, 139, 141, 143, 145,},};
1

you cant have static variables in struct

2 Comments

That doesn't compile with gcc.
As a side note, trailing comma is allowed in enums but not in structs. This is an obscure C99/C11 feature.
1

Probably the links below might help you as well

Static Const Initialised Structure Array in C++ Class

c++ Initializing a struct with an array as a member

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.