Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"error expected expression before '{' token"

I’m trying to declare global extern array and define it in another file but error is given. Please find the code snippet below

in .h

extern unsigned int HoldingRegisters[2];

in .c

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

HoldingRegisters={2,0};

"error expected expression before ‘{‘ token"

Thank you in advance

>Solution :

This record in the header file in.h

extern unsigned int HoldingRegisters[2];

is a declaration of an array but not its definition.

In the file in.c apart from the declaration you need also to define the array like

unsigned int HoldingRegisters[2] = {2,0};

This definition must be placed in the file scope outside any function as for example

#include "in.h>

unsigned int HoldingRegisters[2] = {2,0};

//...

Otherwise this record that you shall remove)

HoldingRegisters={2,0};

represents an attempt to assign a braced list to the variable HoldingRegisters of the array type. However arrays are non-modifiable lvalues. That is they do not have the copy assignment operator and moreover in an assignment you need to use an expression and braced lists are not expressions.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading