#162 struct/union support for designated initializers

closed-accepted
None
5
2011-03-28
2011-03-26
No

I've added support for C99-style designated initializers to SDCC. To refresh your memory, designated initializers members of structs and unions to be initialized by name. e.g.:

> struct s pi = { .z = "Pi", .x = 3, .y = 3.1415 };

This feature is very handy.

Changes include a unit test in support/regression/tests to ensure that the feature is operating properly(it is). Support for designated initializers with arrays is not yet implemented(not quite as important to me as supporting this for structs and unions).

Pretty-printed diff can be found here: <https://github.com/darconeous/sdcc/commit/designated-initializers-patch>

Discussion

  • I'm looking forward to support for designates initializers; it's a feature I'd really like to see in sdcc. I'll have a look at this patch later, but for now I recommend to have a look at RFE #2991122 and the attached patch there. That one adds support for designated initializers for all aggregate types, including arrays, and some thought went into handling corner cases correctly. However it still had some parsing problem, due to which the patch never made it's way into trunk.

    Philipp

     
  • This patch appears to be considerably more simple---likely because I'm just handling structs and unions at the moment.

    I actually just ran thru the full test suite, and I notice that I'm getting failures for some, but not all, of the platforms. I'm not entirely sure how to interpret this result. Further probing seems to indicate that there is something rather wrong with how initialized global-scope structs and unions are being handled.

    i.e.: 'ds390','hc08','host','mcs51-huge', 'mcs51-large' all work fine...

    ... but 'mcs51-medium','mcs51-small','mcs51-stack-auto','mcs51-xstack-auto','ucz80' throw some asserts for sl4 in my test case.

    This seems rather strange. Any idea what could cause this to happen? All other regression tests pass.

     
  • Well, it turns out the reason my patch was so much more simple was because I didn't read the designated initializer spec. :)

    I've started working on the patch given in RFE #2991122 and I'm now trying to make sure that it works without regressions.

    I've got it working now with no pre-existing regressions, but it isn't quite passing the new designated initializer test yet.

     
  • I just attached an updated diff of cananian's designated initializer changes(RFE #2991122), with regressions fixed.

    You can have a look at the diff on github here: https://github.com/darconeous/sdcc/commit/sf-patch-2991122-2

    These changes should be much better than my original changes.

     
  • Applied in #6366.

    Thanks to C. Scott and R. Quattlebaum for bringing sdcc a bit closer to standard compliance.

    Philipp

     
    • assigned_to: nobody --> spth
    • status: open --> closed-accepted