【问题标题】:test.c:51:4: error: incompatible types when assigning to type ‘blk from type ‘void *’test.c:51:4:错误:从“void *”类型分配给“blk”类型时不兼容的类型
【发布时间】:2015-02-21 01:54:35
【问题描述】:
    typedef struct abc{

        int a;
        char b;

    }abc;

    typedef abc bkl[1];
    .
    .
    .

    blk b;

b=shmat(shmid, NULL, 0); //This error that (Void *) to blk 
                              //But anyway blk is pointer,it isnt ? 

blk *b;
b=shmat(shmid, NULL, 0); //This is correct, why? b pointor to pointer

谢谢。

【问题讨论】:

  • 不要 typedef 数组类型。你得到的只是这种问题。而且我什至不会 typedef 指针指向任何东西。把变量声明中的*全部写下来,会容易很多。

标签: c types struct void-pointers


【解决方案1】:
blk b;

等同于:

abc b[1];

b 不是您使用它的意义上的指针。

b = shmat(shmid, NULL, 0);

不正确,因为您不能将指针分配给数组。这就是错误的方式,下面是错误的。

int arr[3];
arr = malloc(sizeof(int)*10);

【讨论】:

    猜你喜欢
    • 2018-11-12
    • 1970-01-01
    • 2016-04-16
    • 2013-06-01
    • 1970-01-01
    • 2016-01-23
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多