While SDCC supports assignment and return of structs, it cannot yet initialize variables by a returned struct:
typedef struct {
char c;
} s;
s f(void);
void g(void)
{
s s1 = f();
}
fails to compile:
philipp@notebook6:/tmp$ ~/sdcc-trunk/sdcc/bin/sdcc -mstm8 test.c
test.c:9: error 69: struct/union/array '': initialization needs curly braces
-:0: warning 85: in function g unreferenced local variable : 's1'
This appears to be related to [bugs:#3121]. Initializer list handling blindly assumes that everything without curly braces has to be of a primitive type and cannot be a struct.
Related
Bugs: #3121
The patch I posted in [bugs:#3121] appears to work here, too.
The generated code should work (but is not very efficient, an optimization could eliminate the extra copy).
Related
Bugs: #3121
Implemented in [r15189].
Related
Commit: [r15189]