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

A place of insane ideas, nothing to see here.
Post Reply
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

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

Post 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
Post Reply