0

Hey Guys I got a Compile Error in my C Project with a Function Pointer.

Thank you for your help :)


Folder Structure:

Main Folder: enter image description here

Lib Folder: enter image description here

Heder Folder:

Path : C-Lib/Headers

File(s) : ShowPointer.h


Code (Main.c):

#include <stdio.h>
#include "./Headers/ShowPointer.h"

int main(){
    printf("Hej this is written in VIM some C code.\n");
    getchar();

}

Code (ShowPointer.c):

#include <stdio.h>
#include "../Headers/ShowPointer.h"

void ExPointer(int *pPointer, int *pPointerMax){
    for (int i = *pPointer; i<*pPointerMax; i++){
        printf("%d. %d %p\n", i, *pPointerMax-i, pPointerMax);
    }
    getchar();
}

Code (ShowPointer.h):

#ifndef SHOWPOINTER_FILE
#define SHOWPOINTER_FILE

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

#endif

Compile: I do Compile this Project whit this code:

gcc -o main main.c Lib/ShowAddress.c

Error: Out come of the Compile error text (code):

In file included from main.c:2:0:
./Headers/ShowPointer.h:4:25: error: expected declaration specifiers or ‘...’ before ‘*’ token
 typedef void ExPointer (*)(int , int);
                         ^
In file included from Lib/ShowAddress.c:2:0:
Lib/../Headers/ShowPointer.h:4:25: error: expected declaration specifiers or ‘...’ before ‘*’ token
 typedef void ExPointer (*)(int , int);

Sorry for me bad English.

2
  • What is that typedef even supposed to do? Commented Apr 29, 2017 at 21:46
  • The header declares ExPointer to be the type of a pointer to a function that accepts two int arguments and returns void. ShowPointer.cpp defines (not just declares) ExPointer to be an actual function that accepts two pointers to int as arguments, and returns `void. There is no relationship whatsoever between the declaration in the header and the definition, but there needs to be. Commented Apr 30, 2017 at 1:07

1 Answer 1

1

You want

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

How to create a typedef for function pointers

Sign up to request clarification or add additional context in comments.

2 Comments

Now i get this problem : Lib/ShowAddress.c:4:6: error: ‘ExPointer’ redeclared as different kind of symbol void ExPointer(int *pPointer, int *pPointerMax){ ^ In file included from Lib/ShowAddress.c:2:0: Lib/../Headers/ShowPointer.h:4:16: note: previous declaration of ‘ExPointer’ was here typedef void (*ExPointer)(int , int); But Thanks for help
Perhaps it isn't clear then what you're trying to do. If ExPointer is an actual function, then you can't create a function pointer typedef with the same name. You might want to clarify by editing your original post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.