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.

Archmede
  • 1,592
  • 2
  • 20
  • 37
h3e
  • 15
  • 4
  • What is that `typedef` even supposed to do? – UnholySheep Apr 29 '17 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. – Peter Apr 30 '17 at 01:07

1 Answers1

1

You want

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

How to create a typedef for function pointers

Community
  • 1
  • 1
Phil M
  • 1,619
  • 1
  • 8
  • 10
  • 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 – h3e Apr 29 '17 at 21:56
  • 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. – Phil M Apr 29 '17 at 22:04