EmbDev.net

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


Author: ravi (Guest)
Posted on:

Rate this post
0 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-

Author: Mark .. (mork)
Posted on:

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

Regards Mark

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.