Using typedef function pointer in C

Nitin Gupta

I am trying to use function pointer, which is somewhat like this:

#include "stdio.h"

typedef void (*func)(int*, int*);


void func1(int *a, int*b)
{
    printf("Func1\n");
}

void func2(int *a, int*b)
{
    printf("Func2\n");
}

void func3(int *a, int*b)
{
    printf("Func3\n");
}

int main()
{
    int i;
    func f[] = {
      func1, func2, func3
    };
    printf("Hello\n");

    for(i=0; i< 3; i++)
    {
        func fn = f[i];
        *(fn)(&i, &i);
    }
    return 0;
}

I am always getting error: "void value not ignored as it ought to be"

Do not know, how to overcome this. Can anybody please help?

P0W

You need to use like following :

(*fn)(&i, &i);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

typedef and pointer to function in C

From Dev

C/C++: using a typedef'd function pointer to *declare* a function

From Dev

How do I declare a function that returns a pointer to a function that returns a function pointer without using a typedef in C?

From Dev

Typedef for a pointer to a C function inside C++

From Dev

how to declare function pointer using typedef

From Dev

Using a pointer to function pointers without typedef?

From Dev

C: Function pointer inside a typedef struct

From Dev

How to create a "typedef to a function pointer" in C#?

From Dev

C++ typedef function pointer and declare a pointer in one statement

From Java

Typedef function pointer?

From Dev

C - the typedef function used as a pointer in the argument of another function

From Dev

Using a pointer variable typedef

From Dev

Using a pointer variable typedef

From Dev

C typedef: pointer to struct

From Dev

using vs typedef pointer-to-noexcept-function inconsistency

From Dev

typedef a function interface (not function pointer)

From Dev

error C2823: a typedef template is illegal - function pointer

From Dev

pointer to function to structure, pointer to function to typedef

From Dev

dereferencing pointer to incomplete type error when using typedef struct in C

From Dev

TypeDef with Function Pointer: Function does not Exist

From Dev

C++ typedef function definition as a class member to use later for function pointer?

From Dev

Declaring a typedef for a function returning a struct pointer?

From Dev

How to do a function pointer cast without a typedef?

From Dev

Checking typedef defined function pointer for null

From Dev

How to typedef a function pointer with template arguments

From Dev

Typedef function pointer - differences between use & or not use it

From Dev

Are infinite typedef function pointer inheritances possible?

From Dev

How do i use typedef in c++ on a function pointer that must return an class template?

From Dev

Initial typedef struct pointer (C/C++)

Related Related

  1. 1

    typedef and pointer to function in C

  2. 2

    C/C++: using a typedef'd function pointer to *declare* a function

  3. 3

    How do I declare a function that returns a pointer to a function that returns a function pointer without using a typedef in C?

  4. 4

    Typedef for a pointer to a C function inside C++

  5. 5

    how to declare function pointer using typedef

  6. 6

    Using a pointer to function pointers without typedef?

  7. 7

    C: Function pointer inside a typedef struct

  8. 8

    How to create a "typedef to a function pointer" in C#?

  9. 9

    C++ typedef function pointer and declare a pointer in one statement

  10. 10

    Typedef function pointer?

  11. 11

    C - the typedef function used as a pointer in the argument of another function

  12. 12

    Using a pointer variable typedef

  13. 13

    Using a pointer variable typedef

  14. 14

    C typedef: pointer to struct

  15. 15

    using vs typedef pointer-to-noexcept-function inconsistency

  16. 16

    typedef a function interface (not function pointer)

  17. 17

    error C2823: a typedef template is illegal - function pointer

  18. 18

    pointer to function to structure, pointer to function to typedef

  19. 19

    dereferencing pointer to incomplete type error when using typedef struct in C

  20. 20

    TypeDef with Function Pointer: Function does not Exist

  21. 21

    C++ typedef function definition as a class member to use later for function pointer?

  22. 22

    Declaring a typedef for a function returning a struct pointer?

  23. 23

    How to do a function pointer cast without a typedef?

  24. 24

    Checking typedef defined function pointer for null

  25. 25

    How to typedef a function pointer with template arguments

  26. 26

    Typedef function pointer - differences between use & or not use it

  27. 27

    Are infinite typedef function pointer inheritances possible?

  28. 28

    How do i use typedef in c++ on a function pointer that must return an class template?

  29. 29

    Initial typedef struct pointer (C/C++)

HotTag

Archive