This article has some issues, the first struct in Example #1 is only compiled by GCC with a size of 2 if it has the packed attribute. Other compilers may behave differently which is exactly why bit-fields should be avoided. The behavior of bit-fields even changes between compiler versions, for example:
"""Packed bit-fields of type char were not properly bit-packed on many targets prior to GCC 4.4. On these targets, the fix in GCC 4.4 causes an ABI change. For example there is no longer a 4-bit padding between field a and b in this structure:
struct foo
{
char a:4;
char b:8;
} __attribute__ ((packed));
There is a new warning to help identify fields that are affected: foo.c:5: note: Offset of packed bit-field 'b' has changed in GCC 4.4
""" (https://gcc.gnu.org/gcc-4.4/changes.html)Also, the code in Application #3 isn't using bit-fields at all (the definition of GPIO_P_TypeDef is here: https://github.com/SiliconLabs/Gecko_SDK/blob/master/platfor...)