Here is a test program:
#include <stdio.h>
void test(int *tmp);
main()
{
unsigned long i=789;
printf("before test(), i = %ld\n", i);
test((int *)&i);
printf("after test(), i = %ld\n", i);
}
void test(int *tmp)
{
printf("in test(), *tmp=%d\n", *tmp);
*tmp = 123;
printf("in test(), *tmp=%d\n", *tmp);
}
The test program runs on AIX(32bit), Solaris, Linux, HP UX and I get the same correct output like below:
#gcc test.c -o tst
# ./tst
before test(), i = 789
in test(), *tmp=789
in test(), *tmp=123
after test(), i = 123
#
But for AIX (64bit), I get:
# gcc -maix64 test.c -o tst
# ./tst
before test(), i = 789
in test(), *tmp=0
in test(), *tmp=123
after test(), i = 528280978197
#
I know this is concerned with the data alignment for 64bit system. In my opinion there must be some patches or methods to fix it, but I am still not sure what it is.
Any suggestion will be appreciated.
#include <stdio.h>
void test(int *tmp);
main()
{
unsigned long i=789;
printf("before test(), i = %ld\n", i);
test((int *)&i);
printf("after test(), i = %ld\n", i);
}
void test(int *tmp)
{
printf("in test(), *tmp=%d\n", *tmp);
*tmp = 123;
printf("in test(), *tmp=%d\n", *tmp);
}
The test program runs on AIX(32bit), Solaris, Linux, HP UX and I get the same correct output like below:
#gcc test.c -o tst
# ./tst
before test(), i = 789
in test(), *tmp=789
in test(), *tmp=123
after test(), i = 123
#
But for AIX (64bit), I get:
# gcc -maix64 test.c -o tst
# ./tst
before test(), i = 789
in test(), *tmp=0
in test(), *tmp=123
after test(), i = 528280978197
#
I know this is concerned with the data alignment for 64bit system. In my opinion there must be some patches or methods to fix it, but I am still not sure what it is.
Any suggestion will be appreciated.