- How can I disable it specifically for functions that handle the misalignment? (safe_unaligned_val_16/32/64 - constructs the output by
manually taking byte after byte like memcpy)
The C language specifies neither the diagnostic nor any way to work around it. It does not even have a sense of structure packing, leaving most details of the layout of structures to implementations' discretion.
Since you seem to be interested specifically in GCC, you would probably find that implementation's pragmas for influencing diagnostics to be of use for the purpose. In particular, the you would probably find it convenient to do
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwhatever-the-relevant-option-is"
// function or functions ...
#pragma GCC diagnostic pop
- Does GCC make some optimization if I pass struct pointers to a function? I've noticed some optimizations like when you have a struct
with 4 bytes of primitive types, it just passes that value to a single
32 bit register when the function doesn't change the value of the
primitives in. Elaborate if you know anything like this ^
I am not aware of that specific optimization, but implementations have great freedom to optimize. It is up to the compiler to ensure that the semantics of the resulting program are equivalent to those C describes for the source code presented to it. Such an optimization might indeed be valid and useful for a function that satisfies a rather stringent set of requirements, but not modifying the pointed-to value is not sufficient for such an optimization to be safe.