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

A place of insane ideas, nothing to see here.
User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

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

Postby Giovanni » Sun Dec 10, 2017 6:19 pm

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

Return to “Safer C”

Who is online

Users browsing this forum: No registered users and 6 guests