EmbDev.net

Forum: ARM programming with GCC/GNU tools Function pointer on arm S3C2400 (mini2440 board)


von ravi (Guest)


Rate this post
useful
not useful
Hi All,

     I am trying to compile some simple programs on mini2440 with linux
burned on it

program1: Test.c
------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void sub (float, float);
void add (float, float);

void (*p[2])(float, float) = {sub,add};
int main ()
{
   float a;
   float b;
   a = 30;
   b = 10;
   p[0](a,b);
   p[1](a,b);

}

void sub (float a,float b)
{
printf ("I am in sub\n");
b = a-b;
printf ("substraction is %f\n",b);
}

void add (float a,float b)
{
printf ("I am in add\n");
b = a+b;
printf ("I am in add %f\n",b);
}
------------------------------------------------------------------------
I compiled abive programs as

#arm-none-linux-gnueabi-gcc -mfloat-abi=soft Test.c -o Test

Above program does not work. While running it gives error of illegal
operation.
but program below works fine.

program2:Test.c
------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void sub (float, float);
void add (float, float);

int main ()
{
   float a;
   float b;
   a = 30;
   b = 10;
   add(a,b);
   sub(a,b);

}

void sub (float a,float b)
{
printf ("I am in sub\n");
b = a-b;
printf ("substraction is %f\n",b);
}

void add (float a,float b)
{
printf ("I am in add\n");
b = a+b;
printf ("I am in add %f\n",b);
}
------------------------------------------------------------------------ 
-

I compiled both of them with same options. Only difference is that one 
uses
function pointers in place of direct function call. But I receive 
illegal
operation in first program which used function pointers.

Anyone has any idea why such thing is happening. I think there is some
option which I need to use while compilation. Please help.

Thanks
-R/\\/I-

von Mark .. (mork)


Rate this post
useful
not useful
Try adding -mcpu=arm920t to compiler options. AFAIK ARMv5 is the default 
architecture arm-none-linux-gnueabi-gcc uses.

Regards Mark

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.