Page 1 of 1

[NO REPLY] Structures, unions and enums (rev #3, 2018-1-15)

Posted: Sun Dec 10, 2017 6:19 pm
by Giovanni
Declaration changes

A structure/union/enum name is ALSO a type so no need to typedef structures/unions/enums. This means that the following is possible:

Code: Select all

struct my_struct_type = {
  my_struct_type *ptr;
};
my_struct_type my_var;


  • Making a typedef of a struct, union or enum creates a derived type (related).

Enhancements

  • It is possible to extend structures/unions using the new extends keyword, the two types are related:

Code: Select all

struct my_struct_type extends ancestor_struct_type {
  ...
}


Fields are appended to the fields of the parent struct/union.

  • Anonymous structures/unions are allowed.
  • Empty structures are allowed.
    • The size of an empty structure is zero.
  • Structures fields can be qualified as "packed", in this case there will be no alignment enforcement for the field and the compiler will take care of loading/storing unaligned data.
    • It is not possible to take pointers to packed fields.
    • Packed is an attribute of fields not structures, structures are aligned normally unless are packed fields of other structures.

Giovanni