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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:42:59+00:00 2026-05-26T02:42:59+00:00

Consider the following C program: int main(void) { char string[10] __attribute__ ((aligned(32))); int i;

  • 0

Consider the following C program:

int main(void)
{
    char string[10] __attribute__ ((aligned(32)));
    int i;
    int *intp = (int*)(string + 1 );

    printf("string: 0x%x, intp: 0x%x\n", string, intp);

    for (i=0; i<10; i++)
    {
        string[i] = 10;
    }
    dump(string);

    printf("*intp: 0x%x\n", *intp);

    *intp = 0xEEEEEEEE;
    dump(string);

    return 0;
}

So I was basically forcing CPU to access a 32 bit data (int) at a misaligned address. TBH I was hoping for a segfault on my ARM9 board. But instead I got some interesting/confusing result:

After setting intp to 0xEEEEEEEE, dumping of string shows:

 0xee, 0xee, 0xee, 0xee, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa    

So the code actually changed the first element in string! Why?

Thanks,

  • 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-05-26T02:42:59+00:00Added an answer on May 26, 2026 at 2:42 am

    Most probably the CPU “rounds” misaligned addresses, so that when you pass a misaligned address to a certain instruction, the hardware finds the closest boundary and performs the designated operation on that address.

    This might really answer your question:

    On the ARM and StrongArm, if you ask for a non-aligned word and you
    don’t take the alignment trap, then you get the aligned word rotated
    such that the byte align you asked for is in the LSB. Eg,

    Consider:
            Address: 0  1  2  3  4  5  6  7
            Value  : 10 21 66 23 ab 5e 9c 1d
    
    Using *(unsigned long*)2 would give:
            on x86: 0x5eab2366
            on ARM: 0x21102366
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider the following code: class Program { static void Main(string[] args) { Department deathStar
Lets us consider the following program : #include <stdlib.h> int main(int argc, char **argv){
Consider the following code: namespace ConsoleApplication1 { class Program { static void Main(string[] args)
Consider the following small program: #include <cstdio> int main() { printf(%d\n, 1); std::printf(%d\n, 2);
Consider the two following programs: program one int main() { printf( hello\n ); }
Consider the following code: #include <stdio.h> int main (void) { char str1[128], str2[128], str3[128];
Consider the following program: $x=12345678901.234567000; $y=($x-int($x))*1000000000; printf(%f:%f\n,$x,$y); Here's what is prints: 12345678901.234568:234567642.211914 I was
Consider the following code: #include <stdio.h> #include <ctype.h> char* Mstrupr(char* szCad); int main() {
Consider the following program: #include <cstddef> #include <cstdio> void f(char const*&&) { std::puts(char const*&&);

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.