我想從舊庫的代碼中刪除以下警告我的工作: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。 –