Menu

#797 Initialize struct from return value

None
closed-fixed
None
5
2024-12-22
2022-03-16
No

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'

Discussion

  • Benedikt Freisen

    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

  • Philipp Klaus Krause

    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

  • Philipp Klaus Krause

    • status: open --> closed-fixed
    • assigned_to: Philipp Klaus Krause
    • Group: -->
     
  • Philipp Klaus Krause

    Implemented in [r15189].

     

    Related

    Commit: [r15189]


Log in to post a comment.

MongoDB Logo MongoDB