我想从旧库的代码中删除以下警告我的工作:GCC:“警告:分配从兼容的指针类型”
Image.c:171:22: warning: assignment from incompatible pointer type [enabled by default]
image->f.get_pixel = get_pixel1;
我shortend在下面的文本代码使它更易于阅读!
现在,我认为get_pixel1是一个函数指针,这个函数:
#define READ_BIT(image, x, y) \
(image->data[(y * image->bytes_per_line) + (x >> 3) ] & (1 << (x & 7)))
static unsigned long
get_pixel1(XImage *image, unsigned int x, unsigned int y)
{
return READ_BIT(image, x, y) != 0;
}
虽然f.get_pixel在这里被定义:
typedef struct _XImage {
int width, height; /* size of image */
/* snip */
struct funcs { /* image manipulation routines */
struct _XImage *(*create_image)(/*snip*/);
/* snip */
unsigned long (*get_pixel) (struct _XImage *, int, int);
/* snip */
} f;
} XImage;
我的问题是什么我要在这里投删除问题标题中的警告:
image->f.get_pixel = (?????)get_pixel1;
或者除了ca外还有其他的事情要做吗? ST?
可能是您的函数指针需要signed int,而您的函数使用unsigned int。 –