From: Erwin Authried (eauth@softsys.co.at)
Date: Fri Feb 23 2001 - 06:12:31 EST
> kimsh@mail.rednix.com wrote:
> Hello,
>
> I am using Aplio's uclinux and toolchains for ARM7TDMI.
>
> I executed the following program.
>
>
> int i = 1234;
> int *ip = &i;
>
> main()
> {
> printf("*ip = %d\n", *ip);
> printf("ip = 0x%x, &i = 0x%x\n", ip, &i);
> }
>
>
> The first printf statement outputs a garbage value, but not 1234.
> Also, the second printf statement prints the different values for ip and &i.
>
> It seems that the initailization of global variables to the addresses of
> any other variables does not work.
>
> A program uses global variables of fuction pointer type, and initializes
> them.
> So, the program does not call the functions using that function pointers,
> correctly.
>
> Is there any solution for that problem?
>
If you look at the asm output of the two variable declarations, you can see what's
going on: The variable "ip" is initialized with "i". This is wrong because
the adress of "i" isn't known at compile time. The value can only determined at
runtime when the variable base register is available in r9. The same kind of problem
is available in m68k-pic-coff too. For now, simply avoid initializing variables with
adresses of variables.
-Erwin
@ Generated by gcc 2.96 20000519 (experimental) for ARM/elf
.file "x.c"
gcc2_compiled.:
.global i
.data
.align 2
.type i,object
.size i,4
i:
.word 1234
.global ip
.align 2
.type ip,object
.size ip,4
ip:
.word i
This message resent by the uclinux-dev@uclinux.org list server http://www.uClinux.org/
This archive was generated by hypermail 2.1.4 : Thu Sep 19 2002 - 13:19:31 EDT