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 8266429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:09:25+00:00 2026-06-08T05:09:25+00:00

I am using ARM. I got alignment fault due to read/write in odd offset(we

  • 0

I am using ARM. I got alignment fault due to read/write in odd offset(we knew ARM is 4 byte aligned). All the structs defined in my program is single – byte aligned like

#pragma pack(push, 1)    

typedef struct
{
   char a1;
   int  a2;
   char a3;
}a;

#pragma pack(pop)

I am trying to do

#pragma pack(push, 1)

typedef struct
{
    char a1 __attribute__ ((aligned (4)));
    int  a2;
    char a3;
}a;

#pragma pack(pop) 

the gcc attribute _attribute_ ((aligned (4))) makes no effect.

Note :: The above code is not my actual code. sample scenario. 

so I re-arranged structure member to solve the alignment issue. I want to ensure whether the re-arranging is the possible solution or we can make _attribute_ to work on this scenario. Any other solutions are welcome. Thanks in advance.

  • 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-08T05:09:29+00:00Added an answer on June 8, 2026 at 5:09 am

    You can safely read/write char/int in byte-aligned structs on ARM, compiler take care about alignment. Single problem can occur with alignment issue is with the casting to 32 bit int like this:

    char buf[5];
    char *p = buf + 1;
    *((int *)p) = 1;
    

    Note: if you for some reasons like align some member (from begin of the struct) you can use following trick:

    typedef struct {
        struct {} __attribute__ ((aligned (4)));
        char a1; // offset is 4
        int  a2; // offset is 5
        char a3; // offset is 9
    } a;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm debugging some odd ARM exceptions in an embedded system using the IAR workbench
I'm developing an embedded application using GCC/G++ compiled for arm-eabi. Due to resource constraints,
This is specifically related to ARM Neon SIMD coding. I am using ARM Neon
I am using a ARM Cortex-M3, and a Cortex-M4. I want to make use
I'm trying to program ARM using Eclipse + CDT + yagarto (gnu toolchain) +
I am using the Microsoft ARM Assembler v15.00.20720 (armasm.exe) that came with Visual Studio
Using VS 2008, the target environment is Windows CE with an ARM processor if
I am using OpenCV DFT in mobiles and tablets, let's say ARM devices. The
I have an application which i build using gcc on linux host for ARM
We're working on a C program compiled with arm-eabi-gcc under Linux. We're using a

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.