我完全陷入了困境.我在3个文件中有以下代码:
文件mixer_oss.c
#include "mixer.h"
static char *devices[] = SOUND_DEVICE_NAMES;
static char **oss_get_device(void)
{
int i, o, devs, res;
char **result;
if ((ioctl(fd, SOUND_MIXER_READ_RECMASK, &devs)) == -1) {
return NULL;
} else {
result = malloc(sizeof(char*)*SOUND_MIXER_NRDEVICES);
o = 0;
for (i=0; i < SOUND_MIXER_NRDEVICES; i++) {
res = (devs >> i)%2;
if (res) {
result[o] = malloc(strlen(devices[i])+1);
sprintf(result[o], "%s", devices[i]);
o++;
}
result[o] = NULL;
}
}
return result;
}
struct mixer oss_mixer = {
.get_device = oss_get_device,
};
Run Code Online (Sandbox Code Playgroud)
文件mixer.h
#ifdef __cplusplus
extern "C" {
#endif
struct mixer
{
char (* get_device) (void);
};
#pragma weak oss_mixer
extern struct mixer oss_mixer;
#ifdef __cplusplus
};
#endif
Run Code Online (Sandbox Code Playgroud)
file mixer.c
#include "mixer.h"
static char null_get_device(void)
{
}
static struct mixer *mixers[] = {
&oss_mixer,
&null_mixer
};
Run Code Online (Sandbox Code Playgroud)
现在,当我编译代码时,这就是我得到的
mixer-oss.c: warning: initialization from incompatible pointer type [enabled by default]
.get_device = oss_get_device,
^
warning: (near initialization for ‘oss_mixer.get_device’) [enabled by default]
Run Code Online (Sandbox Code Playgroud)
请你帮助我好吗?
提前致谢.
char (* get_device) (void);声明一个指向函数的指针,该函数不带参数并返回一个char.
static char **oss_get_device(void)是一个不带参数的函数,并返回指向指针的指针char.
你的函数指针应该像这样声明:
char ** (*get_device)(void);
Run Code Online (Sandbox Code Playgroud)
现在它兼容oss_get_device.
| 归档时间: |
|
| 查看次数: |
753 次 |
| 最近记录: |