Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 12
    Yes, but why was it defined this way? Commented Jan 1, 2014 at 22:51
  • 2
    @nes1983 The programmer may be making assumptions as to the order of the data in the struct and may be using masking to get each portion. If the struct is reordered than the masking my be incorrect. Commented Jan 2, 2014 at 16:58
  • 13
    @Evo510: I’m confused. To use masking, you have to know padding, too, which is not guaranteed by the language. So, you can’t use masks. Am I missing something? Commented Jan 3, 2014 at 19:58
  • @nes1983 I've seen numerical integration code which makes the assumption that all of its inputs are floats in sequential order. You pass it the pointer to the first value to integrate, and the last, and it scans between them. However, you keep the information in a struct because, for everything except integration, it is a more convenient format. Commented Apr 15, 2015 at 6:03
  • 1
    While it will violate the Standard, there is useful reordering method to protect Linux kernel from rootkits/exploits: part of Linux KSPP (kernsec.org/wiki/index.php/Kernel_Self_Protection_Project) is some struct fields randomization/reordering: openwall.com/lists/kernel-hardening/2017/05/26/8 (Introduce struct layout randomization plugin), related paper: sec.taylor.edu/doc/… ("Improved kernel security through memory layout randomization" - DM Stanley - ‎2013) Commented Jun 5, 2017 at 15:47