Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8160707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:20:07+00:00 2026-06-06T18:20:07+00:00

I’ve seen countless questions of the form I don’t like padding how do I

  • 0

I’ve seen countless questions of the form “I don’t like padding how do I turn it off”, but have yet to find anything about forcing the compiler to provide extra padding.

The specific case that I have looks like

struct particle{
  vect2 s;
  vect2 v;
  int rX;
  int rY;
  double mass;
  int boxNum;
};

Where vect2 is a simple struct {double x; double y;} vect2. In order to use SSE2, I need to be able to load a pair of doubles, aligned to 16 byte boundaries. This used to work, until I added the extra int, pushing my struct size from 48 bytes to 56 bytes. The result is segfaults.

Is there some kind of compiler directive I can use that either says “pad this struct to make it a multiple of 16 bytes long”, or “this struct has an alignment of 16-bytes”? I know I could do it manually (tacking on an extra char[12], for example), but I’d really rather just tell the compiler(GCC, preferably ICC compatible), and not have to do it manually if I change the struct in future.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:20:07+00:00Added an answer on June 6, 2026 at 6:20 pm

    I’m adding my own answer to this, in case someone comes looking for a solution. Mark’s solution is a neat one, and fulfills the automatic requirement, but it is not when I ended up going with. I wanted to avoid this, which is why I asked the question, but there is a “trivial” solution:

    struct particle{
      vect2 s;
      vect2 v;
      int rX;
      int rY;
      double mass;
      int boxNum;
      char padding[12];
    };
    

    By manually checking the current size of the struct, you can add an appropriate number of chars, (or anything else, but char‘s let you do it in bytes), to make it the right size. This showed the best performance, as well as simplicity, even though it does require updating every time the struct changes. In this case that is fine, although if you had a struct that could change size depending on options, that would be problematic.

    Note that my struct was 56 bytes, and I added 12 to make it 64. That math doesn’t work, because the trailing int was already being padded out by 4 bytes to the 8-byte boundary; the struct was actually only 52 bytes before. Adding only 5 chars would have worked, by making the struct 57 bytes long, which would have been padded out to 64, but that is not as nice a solution, which is why I used 12 to make it work out exactly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have two tables with like below codes: Table: Accounts id | username |
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.