I have been implementing a control software in C programming language. One of
the software modules represents a communication table for some proprietary
communication protocol. Each record in this table has one item (among others)
consisting of 8 bits. This item represents properties associated to this record.
Each record can has below given properties:
reported,
event_logged,
time_logged,
archived,
global
I need to define the communication table and for sake of readibility I don't
want to fill the properties of each record with values 0-31. My idea was to
at first define below given bit masks for individual bits in the properties
byte:
#define REPORTED 0x10
#define EVENT_LOGGED 0x08
#define TIME_LOGGED 0x04
#define ARCHIVED 0x02
#define GLOBAL 0x01
Then I wanted to define a macro with parameters which will prepare the content
of the properties based on human readable values
#define Create_properties(reported, event_logged, time_logged, archived, global){ \
(uint8_t)reported | (uint8_t)event_logged | (uint8_t)time_logged | \
(uint8_t)global \
}
The planned usage is following. For example one of the records in the communication
table will be event logged and time logged so I will write the macro in this manner
Create_properties(0, EVENT_LOGGED, TIME_LOGGED, 0, 0, 0)
and the expected result is 01100. I have been facing a problem that I am not
able to compile this source code. I always receive compiler error
"braces around scalar initializer". I have been using the gcc compiler. Does
anybody know why does this error occur? Thanks for any ideas.
Best Answer
Curly braces
{}
are not used for macro definitions. Try removing them and see if it works: