LWN.net Logo

Object-oriented design patterns in the kernel, part 1

Object-oriented design patterns in the kernel, part 1

Posted Jun 2, 2011 14:30 UTC (Thu) by pixelbeat (guest, #7440)
In reply to: Object-oriented design patterns in the kernel, part 1 by juliank
Parent article: Object-oriented design patterns in the kernel, part 1

Well by my analysis in the above link, GCC does init the padding to zero. I.E. it seems GCC interprets 6.7.8 to trump 6.2.6.
I'd be very interested if there was a counter example in the wild


(Log in to post comments)

Object-oriented design patterns in the kernel, part 1

Posted Jun 2, 2011 16:19 UTC (Thu) by juliank (subscriber, #45896) [Link]

> Well by my analysis in the above link, GCC does init the padding to zero.
Did you actually enable optimizations when testing?

> I'd be very interested if there was a counter example in the wild

https://lwn.net/Articles/417989/
https://lwn.net/Articles/417994/

Object-oriented design patterns in the kernel, part 1

Posted Jun 3, 2011 1:59 UTC (Fri) by pixelbeat (guest, #7440) [Link]

> Did you actually enable optimizations when testing?
That is immaterial as optimizations may zero the padding.
The interesting case to test is the non optimized case.

> https://lwn.net/Articles/417989/
> https://lwn.net/Articles/417994/
They concur with my testing I think.
I.E. only in the case where all members are specified
in the initializer list, is the padding not zeroed.

Object-oriented design patterns in the kernel, part 1

Posted Jun 2, 2011 18:00 UTC (Thu) by nix (subscriber, #2304) [Link]

Well, you could check the code, or (more practically) GCC's intermediate representations, both of which make it fairly clear that GCC emits initializations for every field independently, then subjects them all to optimization just as if you'd written them as separate statements. Sometimes (especially for large structures) this may lead to initializations being merged and blatting over gaps: very often, it does not.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds