Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash define for ALIGN_TYPE can be dynamic #94

Closed
GoogleCodeExporter opened this issue Oct 14, 2015 · 4 comments
Closed

Hash define for ALIGN_TYPE can be dynamic #94

GoogleCodeExporter opened this issue Oct 14, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

Instead of using this:

  #if defined(__hppa__) || defined(__sparc__)
  #define ALIGN_TYPE double                   /* the data type to use for alignment */
  #else
  #define ALIGN_TYPE void *                   /* the data type to use for alignment */
  #endif

Do something like this:

  extern int Align_Size;

...

  struct __CHECK_ALIGNMENT__
  {
      char fil;
      double val;
  };

  int Align_Size = offsetof(struct __CHECK_ALIGNMENT__, val);

Original issue reported on code.google.com by [email protected] on 27 Jul 2010 at 4:16

@GoogleCodeExporter
Copy link
Author

Thanks for the idea.

I've changed the type from "defect" to "enhancement". Support for offsetof() 
has been patchy in the past. I'll think about this one some more.

Original comment by [email protected] on 27 Jul 2010 at 8:35

  • Added labels: Priority-Low, Type-Enhancement
  • Removed labels: Priority-Medium, Type-Defect

@GoogleCodeExporter
Copy link
Author

I think it should still be defect, since your hard-coded values are incorrect 
for many platforms.
You can implement offsetof yourself, if certain complies don't provide it.

Original comment by [email protected] on 27 Jul 2010 at 9:28

@GoogleCodeExporter
Copy link
Author

After testing on as many platforms as I could, I realized you actually need 3 
values: 

Align_Size - For member alignment
Align_Tail - For tail padding
Align_Special - For special tail padding (Pad tail with this value when double 
is first member)

Here's some example code to calculate each value:


struct __CHECK_ALIGNMENT_MEMBER__
{
    char fil;
    double val;
};

#define ALIGN_SIZE ((char*)&(*(struct __CHECK_ALIGNMENT_MEMBER__*)0).val - 
(char*)&(*(struct __CHECK_ALIGNMENT_MEMBER__*)0).fil)
const int Align_Size = ALIGN_SIZE;

struct __CHECK_ALIGNMENT_TAIL__
{
    char align[ALIGN_SIZE];
    double val;
    char fil;
};

const int Align_Tail = sizeof(struct __CHECK_ALIGNMENT_TAIL__) - 
((char*)&(*(struct __CHECK_ALIGNMENT_TAIL__*)0).fil - (char*)&(*(struct 
__CHECK_ALIGNMENT_TAIL__*)0));

struct __CHECK_ALIGNMENT_SPECIAL__
{
    double val;
    char fil;
};

const int Align_Special = sizeof(struct __CHECK_ALIGNMENT_SPECIAL__) - 
((char*)&(*(struct __CHECK_ALIGNMENT_SPECIAL__*)0).fil - (char*)&(*(struct 
__CHECK_ALIGNMENT_SPECIAL__*)0));

Original comment by [email protected] on 1 Aug 2010 at 3:02

@GoogleCodeExporter
Copy link
Author

I've implemented this a slightly different way in r532, but the general idea is 
similar.

Original comment by [email protected] on 15 Feb 2011 at 4:38

  • Changed state: WontFix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant