User: Password:
|
|
Subscribe / Log in / New account

Object-oriented design patterns in the kernel, part 2

Object-oriented design patterns in the kernel, part 2

Posted Jun 8, 2011 4:52 UTC (Wed) by jzbiciak (subscriber, #5246)
In reply to: Object-oriented design patterns in the kernel, part 2 by cmccabe
Parent article: Object-oriented design patterns in the kernel, part 2

I don't know if the syntax for forcing alignment is standardized yet.

What if you just made it an array of "double" or "long double"? Or, an array of a union of all of the "large" types, so you're guaranteed to get the most restrictively aligned type on the platform?

typedef union
{
    long long   ll;
    double      d;
    long double ld;
    void       *vp;
    void      (*fp)(void);  /* function pointer */
} align_u;

Then replace char end[0] __attribute__((aligned(4))); with align_u end[0];. Wouldn't that work?


(Log in to post comments)

Object-oriented design patterns in the kernel, part 2

Posted Jun 8, 2011 13:16 UTC (Wed) by nix (subscriber, #2304) [Link]

That does indeed work and is exactly what I did. A hallowed ancient trick: I don't know *how* long ago I first saw it. Decades back.


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