5 ms·
Also worth teaching: -fno-strict-aliasing.
by commandersaki 4y ago
Also worth teaching: -fno-strict-aliasing.
- lifthrasiir 4y agoThere is a comment mentioning this. I do have a somewhat different view that you should minimize the number of "reinterpreting" casts (stealing the C++ terminology) in general, which is often ill-advised at the first place. This practice frequently eliminates the need for -fno-strict-aliasing.
- synergy20 4y agofully agree, use strict-aliasing only after profiling and on your bottleneck code, if necessary, otherwise, just use no-strict-aliasing(linux kernel uses it too)
- astrange 4y ago`-fno-strict-aliasing` is even less formally defined than C itself is, so I don't think it's a good tool, you're just hoping it works for your program and not actually checking. UBSan/ASan cleanliness is a better goal.
- synergy20 4y agosince linux kernel depends on it, I would assume it's solid. I do use UBSan/ASan as well, but I can't enable them for production run, and I can with no-strict-aliasing, which is at least safer than without-it.
- einpoklum 4y agoI disagree. That is, when teaching C, I never gave examples avoiding any aliasing, and if it somehow came up, I advised against it. But I don't think it's a good idea to invest teaching time in compiler options regarding aliasing; it's too specific for an introductory C course.