c++ - c语言实现顺序栈出错【操作符"="左边的值须为 “左值“
伊谢尔伦
伊谢尔伦 2017-04-17 15:31:32
0
2
505
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
大家讲道理

The more important question than the left and right values ​​​​is: Is it stored in the stack GOBJ or a pointer to GOBJ? From the declaration of GOBJ* st, it seems that you want to store GOBJ, and from the way of calling malloc, it seems that you want to store GOBJ*, and then it becomes confusing.

If you want to store a pointer, then st needs to be declared as GOBJ** st, and malloc does not need to be cast. Then the sentence of pushing onto the stack can be written in array notation:

st->st[st->top] = gobj;
洪涛

Tips you that st->st + st->top is not a legal lvalue, st->st + st->top is just a value, and the lvalue should be a referenceable address.

FromWikipedia

The lvalue has a definite memory address that can be obtained. This means that an lvalue can be a variable or the result of dereferencing a pointer to a specific memory address. For example, the C language expression (4 + 9), when executed, the computer generates an integer value 13, but because the program does not explicitly specify how this 13 is stored in the computer, this expression generates an rvalue. On the other hand, if a C program declares a variable x and assigns x the value 13, then the expression (x) evaluates to 13 and is an lvalue.

How about you try this

GOBJ *tmp = (GOBJ *)(st->st + st->top);
tmp = gobj;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template