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

  • Home
  • SEARCH
  • 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 8397203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:43:47+00:00 2026-06-09T20:43:47+00:00

It is C language.It is written that: typedef struct __attribute__((packed, aligned(4))) Ball { float2

  • 0

It is C language.It is written that:

typedef struct __attribute__((packed, aligned(4))) Ball {
    float2 delta;
    float2 position;
    //float3 color;
    float size;
    //int arcID;
    //float arcStr;
} Ball_t;
Ball_t *balls;

Please tell me what is the meaning of it,and how to use this keyword.

  • 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-09T20:43:49+00:00Added an answer on June 9, 2026 at 8:43 pm

    Before answering, I would like to give you some data from Wiki


    Data structure alignment is the way data is arranged and accessed in computer memory. It consists of two separate but related issues: data alignment and data structure padding.

    When a modern computer reads from or writes to a memory address, it will do this in word sized chunks (e.g. 4 byte chunks on a 32-bit system). Data alignment means putting the data at a memory offset equal to some multiple of the word size, which increases the system’s performance due to the way the CPU handles memory.

    To align the data, it may be necessary to insert some meaningless bytes between the end of the last data structure and the start of the next, which is data structure padding.


    gcc provides functionality to disable structure padding. i.e to avoid these meaningless bytes in some cases. Consider the following structure:

    typedef struct
    {
         char Data1;
         int Data2;
         unsigned short Data3;
         char Data4;
    
    }sSampleStruct;
    

    sizeof(sSampleStruct) will be 12 rather than 8. Because of structure padding. By default, In X86, structures will be padded to 4-byte alignment:

    typedef struct
    {
         char Data1;
         //3-Bytes Added here.
         int Data2;
         unsigned short Data3;
         char Data4;
         //1-byte Added here.
    
    }sSampleStruct;
    

    We can use __attribute__((packed, aligned(X))) to insist particular(X) sized padding. X should be powers of two. Refer here

    typedef struct
    {
         char Data1;
         int Data2;
         unsigned short Data3;
         char Data4;
    
    }__attribute__((packed, aligned(1))) sSampleStruct;  
    

    so the above specified gcc attribute does not allow the structure padding. so the size will be 8 bytes.

    If you wish to do the same for all the structures, simply we can push the alignment value to stack using #pragma

    #pragma pack(push, 1)
    
    //Structure 1
    ......
    
    //Structure 2
    ......
    
    #pragma pack(pop)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an English language forum site written in perl that is continually bombarded
Can software be written (for some specific programming language, platform, etc.) that will inform
I heard that programs written in a functional language tend to scale better. Is
Ok: I edited my question: I heard somewhere that php language is written in
Possible Duplicates: How can a language's compiler be written in that language? implementing a
I've written a compiler that produces JVM bytecode for a custom language. The compiler
What language are ps3 and xbox 360 game written in? Are the games written
I have written grammar for a language (sample code below) //this is a procedure
I have an application written in a language called magic. This application uses MSSQL
I've written an interpreter for my experimental language and know I want to move

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.