Altera Nios II C2H Compiler User Manual
Page 130

7–6
9.1
Altera Corporation
Nios II C2H Compiler User Guide
November 2009
Language
defines three sub-functions,
sub_plus_one()
,
sub_plus_two()
and
sub_plus_three()
. A fourth function,
c2h_fnc()
, returns a pointer to one of the three sub-functions,
depending on the value of the input argument
one_two_or_three
. The
C2H Compiler supports this use of function pointers as long as all four
functions are part of the hardware accelerator.
Example 7–1. Use of Function Pointers Inside the C2H Accelerator
int sub_plus_one(int in)
{
return in + 1;
}
int sub_plus_two(int in)
{
return in + 2;
}
int sub_plus_three(int in)
{
return in + 3;
}
int c2h_fnc(int in, int one_two_or_three)
{
int (*fp)(int);
fp = ((one_two_or_three == 3) ? sub_plus_three :
((one_two_or_three == 2) ? sub_plus_two :
sub_plus_one));
return fp(in);
}
Function Argument Types (Section 6.9.1, Paragraph 13)
Functions must define the types of the arguments passed.
For example, the following declaration of
foo()
is not supported
because the arguments
a,b,
and
c
are not typed:
void foo(a,b,c);
The following function declaration which defines the argument types
inside the function argument list is supported:
void foo(char a, char b, char c);