This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is it possible to partially initialize a struct?

Hi, my question is to ask whether or not it is possible to partially initialize a struct in C language with Keil C166 compiler.

According to C syntax [1], it should be possible to do things like:

struct {
    int a;
    int b;
    int c;
} S = {
    .b = 0,
    .c = 1,
};

In the example above, only the selected members of the structure are given default values, the others are not.

However, the C166 compiler seems not to understand this expression. When compiling, it reports error: MAIN.C(14): error C25: syntax error near '.'

The reason why i am asking this question is because: the Keil compiler by default creates sections ?C_INITSEC and ?C_CLRMEMSEC which store data for START_V2.A66 to clear variables to zero and assign initialized values at CPU start up. So it will save (well, only a little bit) memory in the ?C_INITSEC by inilizing only non-zero varialbes or struct members only.

[1] en.wikipedia.org/.../C_syntax

0