c - 指针类型不兼容的警告

标签 c

我为散列函数编写了这个 block :

#include "debug.h"
#include "hash.h"

unsigned hash_add(unsigned char *name)
{
unsigned h;
for(h=0;*name;h+=name++);
return h;
}

我不断收到:

hashadd.c:7:17: warning: assignment makes integer from pointer without a cast [enabled  by default]

最佳答案

for``h+=name++ 的最后一个表达式是将地址(name 的类型为unsigned char *)分配给 h(unsigned int 类型)。改成

 for(h = 0; *name; h += *name++);  
                        ^Dereference the pointer before assigning to h.

关于c - 指针类型不兼容的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22602446/

相关文章:

python - 我可以阻止 C++ dll 在 Python Ctypes 中加载吗?

可以映射零页或写入地址零吗?

c - 查找两个日期之间的差异 C

c - 引用位时 `pop` 的含义

c - 多个指针和标记和扫描

c - 如何在正确提供 argc、argv、envp 的 NASM 中调用用 C 编写的链接可执行文件中的主要函数

c - 在c中没有strtok的情况下用字符分割字符串

c - 如何在 C 中将文件中的逗号分隔数字读入多维数组

c - 使用三角函数绘制实心圆

c - 在静态数组的情况下,bss 的大小按意外字节递增