-fno-strict-aliasing is so silly, people seem like scared of strict aliasing somehow

like is it that hard to understand the concept of “don’t access some object as a different type unless it’s char *“?

@navi is (my_struct *) (char *) xxx valid then?
@lina if `xxx` is of type `my_struct` (before the casts), yes

but you mostly mean an arbitrary type of `xxx`, which, no

dancing around with casts doesn't help, the rule is applied when you access the memory region, the middle step over `char *` means nothing
@navi yeah i was thinking of arbitrary type, like how in java the compiler will not error on (String) (Object) Integer.valueOf(1)

@lina java works differently than c, likely it’s doing actual conversions here

to which, with non-pointer types in c, e.g. a (double) or (int) cast, it would do the conversions – strict aliasing rules only apply to pointer types because the compiler (rightfully) is allowed to consider two memory regions (pointers) of different types as always being different objects

@navi

likely it's doing actual conversions here

it's not, actually! that piece of code will error at runtime with a ClassCastException because Integer is not a subclass of String. the cast only works because you're allowed to cast down to an ancestor (and Object is the shared ancestor for everything), and to cast up from an ancestor to a derived type -- that is the part that might error out at runtime

@lina @navi comparable to C: double d; (struct my_struct *)&d is allowed (if alignments match, otherwise ub), but dereferencing afterward is ub