赋值使整数警告指针

Sta*_*hta 1 c header gcc-warning

标题:

#ifndef BIT_H_INCLUDE_GUARD
#define BIT_H_INCLUDE_GUARD

typedef unsigned char byte;

typedef struct{
    size_t* size;
    byte* map;
} bit;

bit* bdcteate(byte* size);

#endif /* BIT_H_INCLUDE_GUARD */
Run Code Online (Sandbox Code Playgroud)

资源:

#include <stdlib.h>
#include "bit.h"

bit* bdcreate(byte* size){
    bit* d;
    byte i;
    size_t s = 0;
    for(i = 1; i < size[0]; i++){
        s += (size_t) size[i];
    }
    if(!(d = malloc(sizeof(bit)))){
        return (bit*) NULL;
    }
    if(!(d->size = malloc(sizeof(size_t)))){
        return (bit*) NULL;
    }
    if(!(d->map = malloc(s * sizeof(byte)))){
        return (bit*) NULL;
    }
    *d->size = s;
    return (bit*) d;
}
Run Code Online (Sandbox Code Playgroud)

主要:

#include <stdlib.h>
#include "bit.h"

void main(void){
    byte *b, i;
    byte size = 9;
    b = malloc((size+1) * sizeof(byte));
    b[0] = size;
    for(i = 1; i <= size; i++){
        b[i] = (b[i-1] + 10);
    }   

    bit* dict;
    if(!(dict = bdcreate(b))){ /* warning: assignment makes pointer from integer without a cast */
        exit(EXIT_FAILURE);
    }
    exit(EXIT_SUCCESS);
}
Run Code Online (Sandbox Code Playgroud)

正如您在注释行中看到的那样,我得到"警告:赋值从没有强制转换的整数中生成指针",尽管我尝试明确声明我正在返回指针.

我正在使用gcc(gcc -o test main.c bit.c)进行编译,程序似乎运行正常.

我应该忽略这一点,还是会在我睡觉时回来咬我?

Mat*_*Mat 10

在你的标题中:

bit* bdcteate(byte* size);
        ^ this is a typo
Run Code Online (Sandbox Code Playgroud)

这意味着编译器将bdcreate在main中推断出默认签名,默认签名返回一个int.