Altera_Forum
Honored Contributor
15 years agoPointer help - alignment issue
I need to use a pointer to a long that is not word aligned (I think). Here is sample code
void func(void) { char Test[12] = { 1, 2, 3,4 ,5 ,6, 7, 8, 9, 10, 11, 12}; long * temp; temp = (long *) &Test[0]; printf("Starting at Test[0] *%d = %X\n", temp, *temp); temp = (long *) &Test[1]; printf("Starting at Test[1] *%d = %X\n", temp, *temp); temp = (long *) &Test[2]; printf("Starting at Test[2] *%d = %X\n", temp, *temp); temp = (long *) &Test[3]; printf("Starting at Test[3] *%d = %X\n", temp, *temp); temp = (long *) &Test[4]; printf("Starting at Test[4] *%d = %X\n", temp, *temp); temp = (long *) &Test[5]; printf("Starting at Test[5] *%d = %X\n", temp, *temp); } and the output Starting at Test[0] *50331608 = 4030201 Starting at Test[1] *50331609 = 4030201 Starting at Test[2] *50331610 = 4030201 Starting at Test[3] *50331611 = 4030201 Starting at Test[4] *50331612 = 8070605 Starting at Test[5] *50331613 = 8070605 How come the second value is no 5040302? I am assuming that the compiler is word aligning the pointer (basically anding with 0xFFFFFFFC). I think I need to use long * __unaligned temp; but I get an error expected initializer before "temp" Do I need some include that I missed in the documentation? thanks in Advance