本文介绍了GCC 2.9"左值要求作为分配及QUOT的左操作数;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直空指针玩弄创造这个例子:

I have been playing around with void pointers and created this example:

#include <stdio.h>

struct intint {
    int a;
    int b;
};

struct intshortshort {
    int a;
    short b;
    short c;
};

void fill_me(struct intint **pii, void *piss)
{
    (void*)*pii = piss;                // Question about this line?
}

int main()
{
    struct intint *pii = NULL;
    struct intshortshort iss;
    iss.a = iss.b = iss.c = 13;

    fill_me(&pii, &iss);

    printf("%d..%d\n", pii->a, pii->b);


    return 0;
}

问:

当我使用gcc版本2.95.4一切编译和按预期工作,但gcc版本4.7.3给了我以下错误:

When I'm using gcc version 2.95.4 everything compiles and works as expected, but gcc version 4.7.3 gives me following error:

void_pointer.c:16:17: error: lvalue required as left operand of assignment

时有一个原因增加(无效*),以左值不再被允许的?

Is there a reason why adding (void *) to lvalue is not allowed anymore?

编辑:谢谢您的回答,我想我明白这个问题,但问题的为什么?这是摆在首位OK仍是有趣的

Thank you for answers, I think I understood the problem, but the question "why it was ok in the first place?" is still interesting.

推荐答案

这问题不是关于无效* ,大约是类型转换和左值。

This question isn't about the void*, is about typecast and lvalue.

例如:

#include <stdio.h>

int main()
{
    int n;
    (int)n = 100;
    return 0;
}

这code会引起同样的错误:如需要转让的左操作数左值

this code will causes same error: lvalue required as left operand of assignment.

这是因为 = 运营商需要修改的左值作为其左操作数。

That because the = operator requires a modifiable-lvalue as its left operand.

那么,什么是左值?又有什么修改的左值?请参阅

So, what is the lvalue? and what's the modifiable-lvalue? Please see wikipedia:Value.

这篇关于GCC 2.9&QUOT;左值要求作为分配及QUOT的左操作数;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 21:50