1

I was developing C program to read status of door access. I created a struct in which two arrays were declared. I wanted to initialize the array at the time of definition of that structure. For example,

Struct declaration in .h file:

typedef volatile struct
{

    uint8_t __near const * const people_in_input_ports[8];

    uint8_t __near const * const people_out_input_ports[8];

}GATE_ACCESS_CTRL_BLOCK;

Struct definition in .c file:

GATE_ACCESS_CTRL_BLOCK g_gate_acc_parameters    = { 
    .people_in_input_ports  = {&P12, &P4, &P4, &P4, &P6, &P6, &P6, &P6},                                                
    .people_out_input_ports = {&P14, &P14, &P2, &P14, &P14, &P5, &P5, &P1}
};

Here, P12, P4, P6, P5, P2 and P14 are sfr addresses of corresponding port.

I got the following error.

E0520029:Expected an expression
E0520029:Expected an expression

How to initialize arrays that are declared inside of a structure by using arrays' name?

1

1 Answer 1

1

In my project the C90 standard was selected which doesn't support that kind of initialization in the compiler settings. Changing it to the C99 standard makes it work.

Sign up to request clarification or add additional context in comments.

1 Comment

Or just drop the designated initializers.

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.