Function with two or more entry point
sztfg@yandex.ru
sztfg@yandex.ru
Tue Mar 12 21:56:00 GMT 2013
13.03.2013, 01:16, "James Bowman" <jamesb@excamera.com>:
> This works, and is perhaps close to the idea:
>
> #include <stdio.h>
>
> typedef void (*funcptr)();
>
> funcptr test_print(int pick)
> {
> б б void test_print1()
> б б {
> б б б б printf("print1\n");
> б б }
> б б void test_print2()
> б б {
> б б б б printf("print2\n");
> б б }
> б б return (pick == 1) ? test_print1 : test_print2;
> }
>
> int main ()
> {
> б б funcptr ep1 = test_print(1);
> б б funcptr ep2 = test_print(2);
>
> б б ep1();
> б б ep2();
>
> б б return 0;
> }
>
> --
> James Bowman
> http://www.excamera.com/
No. It prints:
print1
print2
It should print:
print1
print2
print2
This is what I want to do:
#include <stdio.h>
typedef void (*funcptr)();
void test_print1()
{
printf("print1\n");
}
void test_print2()
{
printf("print2\n");
}
void eval_ptr(funcptr *a)
{
while (*a != NULL)
{
(*a)();
a++;
}
}
int main ()
{
funcptr ep1[3] = {test_print1, test_print2, NULL};
funcptr ep2[2] = {test_print2, NULL};
eval_ptr(ep1);
eval_ptr(ep2);
return 0;
}
But i need it in one function with two entry point. I can code this in assembly, but not in C
More information about the Gcc-help
mailing list