English 中文(简体)
汇编c码:错误:作为转让左轮操作所需要的价值
原标题:compiling c code: error: lvalue required as left operand of assignment
  • 时间:2011-05-04 05:37:44
  •  标签:
  • c

When I try to compile some code on gcc 4.4.5, gcc runs into an error on this line:

ORG(e) = DEST(a);

These 2 macros are defined as:

#define ORG(e) ((site_struct *) ODATA(e))
#define DEST(e) ((site_struct *) DDATA(e))

I did not have a problem compiling this on solaris with gcc 3.4.5.

I ve been trying to figure out why it won t compile for quite a while but to no avail. Can anyone point me in the right direction?


From a comment:

ODATA and DDATA are defined as:

#define ODATA(e) ((edge_struct *)((e)&0xfffffffcu))->data[(e)&3]
#define DDATA(e) ((edge_struct *)((e)&0xfffffffcu))->data[((e)+2)&3]
问题回答

我认为,很难相信你可以就太阳能问题汇编。 你的任务左侧是投下的结果。 C语言的投票结果总是r Values。 你们可以把任何东西推向高价值。 很简单。 数值不是物体。 他们没有被存储在记忆中,这就是为什么试图将任何东西分配到高价值中是毫无意义的。 这是C的一个非常根本的事实,因此,我可以认为你可以与任何C汇编者一起汇编。

例如,该法典

int i;
(int) i = 5; /* ERROR */

出于同样的原因,您的法典没有编纂。

很难“确定你的方向是正确的”,因为完全不清楚你试图做什么。 这一转让意味着什么? 为什么你想要在任务两侧投放呢?

Your ODATA() and DDATA() macros evaluate to lvalues (the cast in those macros is to a pointer that s dereferenced to obtain the lvalue). So what needs figuring out is what the original ORG() and DEST() macros do:

#define ORG(e) ((site_struct *) ODATA(e))
#define DEST(e) ((site_struct *) DDATA(e))

Basically they take the lvalues produced by the ODATA() and DDATA() macros and treat them as pointers. GCC 3.4.5 s cast-as-lvalue language extension, which was deprecated in 3.4.5 and removed in 4.0, allows the result of a cast to be used as an lvalue if the operand to the cast is an lvalue. We can emulate that by performing our own pointer/address manipulation and dereferencing. Change the ORG() and DEST() macros to take the address of the lvalues produced by the ODATA() and DDATA() macros, then dereference that address as a pointer to the desired type. This should produce equivalent results in GCC 4.x as you were getting in GCC 3.4.5 with your existing macros:

#define ORG(e) (*((site_struct **) &(ODATA(e))))
#define DEST(e) (*((site_struct **) &(DDATA(e))))

I think that should produce the same behavior that the original code had in GCC 3.4.5 - presumably that s the correct behavior for this application.

A couple of notes:

  • as other answers have mentioned - these macros are a mess, and should be refactored to something more maintainable at the earliest opportunity. But sometimes you just gotta be pragmatic and get a port working.
  • d 对()和DDATA( XIs)稍加修改,将其填入门。 I m并不确定自->>[]操作者具有很高的优先地位以来的必要,但我对表示完全由母体组成的宏观表示不满意:

    #define ODATA(e) (((edge_struct *)((e)&0xfffffffcu))->data[(e)&3])
    #define DDATA(e) (((edge_struct *)((e)&0xfffffffcu))->data[((e)+2)&3])
    

投放的结果是高价值,而不是高价值。 其结果只是“批量”价值,而不是作为价值来源的原始物体。

如何在你的案件中确定事情并非完全清楚。 尤其是,在不了解官方发展援助安排(e)和发展援助安排(e)是什么的情况下,它很难猜测如何从那里着手。

如果你再次试图把一个方向分配给另一个方面,你可以做些什么:

*(site_struct *)a = *(site_struct *)b;

请注意,即使我们投了派双方的席位,我们仍不试图分配投票结果——相反,我们却对正确类型的点置若.闻,然后避开该点,并指定该点人所指的物体。

Edit: okay,在宏观扩大后,我们最后做如下事情:

((site_struct *)((edge_struct *)((e)&0xfffffffcu))->data[(e)&3]) =
((site_struct *)((edge_struct *)((a)&0xfffffffcu))->data[((a)+2)&3]);

我认为,根据这种 she笑,我试图支持至少两个层次的抽象思想,并试图表明所有这一切的意图。 这很接近于只字面编码。 虽然你按要求提供了官方发展援助协定和《发展与贸易法》的定义,但你认为,这种定义不仅需要如此——你需要仔细研究<条码>的界定>,可能的话,还有<条码>现场_struct/code>。 页: 1

为了弥补长篇故事,这看起来像一个相当严重的反向工程案例,几乎不可能预测,在你能够重写/更新标准之前,需要审查和理解多少法典,以便你从现代汇编者那里获得正确结果。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签