Function pointer on arm S3C2400 (mini2440 board)

Guest #1761299
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-

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.