C编译错误指针

时间:2017-04-29 21:43:49

标签: c pointers compiler-errors

嘿伙计我的C项目中有一个带有功能指针的编译错误。

感谢您的帮助:)

文件夹结构:

主文件夹: enter image description here

自定义文件夹: enter image description here

Heder Folder:

路径: C-Lib/Headers

档案:ShowPointer.h

代码(Main.c):

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

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

}

代码(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();
}

代码(ShowPointer.h):

#ifndef SHOWPOINTER_FILE
#define SHOWPOINTER_FILE

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

#endif

编译: 我用这段代码编译这个项目:

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

错误: 出于编译错误文本(代码):

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);

对不起,我的英语不好。

1 个答案:

答案 0 :(得分:1)

你想要

public override string ToString()
{
    return $"[{code},{param},{len}]";
}

How to create a typedef for function pointers