Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can't name the inner struct. So here are the options:

Say that you want this from C:

    struct Foo
    {
      struct Bar {
        int x;
        int y;
      } bar;
    };
    struct Foo f;
    f.bar = (struct Bar) { .x = 123 };
The struct in C3:

    struct Foo
    {
      struct bar {
        int x;
        int y;
      }
    };
    Foo f;
It is correct that we don't get the inner type, but because C3 has inference for {} assignment can happen despite that:

    f.bar = { .x = 123 }; // Valid in C3
You can grab the type using typeof if you want, but interestingly there's also the possibility to use structural casts, which are valid in C3:

    struct HelperStruct
    {
      int x;
      int y;
    }
    HelperStruct test = (HelperStruct)f.bar; // structural cast
But the normal way would be to create a named struct outside if you really need a named struct, e.g.:

    struct Bar { int x, y; }
    struct Foo
    {
      Bar bar;
    };


That ... actually seems reasonable?

If you need it to be first class visible outside, you declare it outside.

I believe I could live with this.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: