You could always align your struct to particular alignment, even in C89. But that alignment must be alignment of one of already existing types. Typically such as void* or double.
#include <assert.h> #include <stdint.h> /* uintptr_t might not exist here in C89 */ union aligned_char_u { char m_char; void* m_pointer; }; typedef union aligned_char_u aligned_char_t; struct my_char_s { aligned_char_t m_char; }; typedef struct my_char_s my_char_t; int main(void) { my_char_t my_char; assert(((uintptr_t)(&my_char.m_char.m_char)) % (sizeof(void*)) == 0); my_char.m_char.m_char = '!'; return my_char.m_char.m_char; } Marek On 2025-08-19 20:44, Thiago Adams wrote:
TCC already implements __attribute__((aligned(8))) For example: struct X { __attribute__((aligned(8))) char c; }; C11 introduced _Alignas, and C23 adds the keyword alignas. The advantage of having it as a keyword rather than as __attribute__ is that attributes are sometimes treated as optional, while alignment is not optional since it directly affects the generated code In my view, the alignas feature is fundamental enough that it should have been part of the language since C89. _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
_______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel