[U-Boot-Users] [PATCH] Functions added to extern for stand alone programs

Wolfgang Denk wd at denx.de
Thu May 24 01:06:52 CEST 2007


In message <e68c55e80705231347w76d86bf8o1a1f6001e93f3f72 at mail.gmail.com> you wrote:
>
> it could't really be that simple, could it? I bet my sintax is wrong,

Maybe.

> and I still do not compleatly understand how the compiler intreprets
> "weak" and "set". But I can see how this would work.

I never used this assembler trickery before myself. So far, I only
played with the C variant of it. Like that:

-> cat foo.c
#include <stdio.h>

int func(int, int);

int main (void)
{
        int i = func (2, 7);

        printf ("i = %d\n", i);

        return 0;
}
-> cat func.c
#include <stdio.h>

int __func (int a, int b)
{
        printf ("Default func called: %d + %d\n", a, b);

        return (a + b);
}

int func(int a, int b) __attribute__ ((weak, alias ("__func")));
-> cat private.c 
#include <stdio.h>

int func (int a, int b)
{
        printf ("Private func called: %d * %d\n", a, b);

        return (a * b);
}
-> gcc -c *.c
-> gcc -o foo foo.o func.o
-> ./foo
Default func called: 2 + 7
i = 9
-> gcc -o bar foo.o func.o private.o
-> ./bar
Private func called: 2 * 7
i = 14



Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It is a human characteristic to love little  animals,  especially  if
they're attractive in some way.
	-- McCoy, "The Trouble with Tribbles", stardate 4525.6




More information about the U-Boot mailing list