- == 系统问题,暂停聊天功能。==
- 【征集】西西河的经济学,及清流措施,需要主动参与者,『稷下学宫』新认证方式,24年网站打算和努力目标
主题:c++ help. -- spin
I got error: cannot bind packed field 'aa.AA::a' to 'int&' as compiling a hello c++ file with gcc3.4,gcc-4.1 and gcc4.2.
#include <iostream>
using namespace std;
struct AA
{
int a;
double b;
}__attribute__((packed));
void func(int &aa, double &bb)
{
aa = 10;
bb = 99.9;
}
int main()
{
struct AA aa;
func(aa.a, aa.b);
cout << aa.a << " " << aa.b;
}
Google does not help much. I grab a setence from gcc/cp/call.c which seems explain this error but I can't understand it. Can anyone help.
from gcc/cp/call.c
/* If the reference is volatile or non-const, we cannot create a temporary. */
/* If the source is a packed field, and we must use a copy constructor, then building the target expr will require binding the field to the reference parameter to the copy constructor, and we'll end up with an infinite loop. If we can use a bitwise copy, then we'll be OK. */
- 相关回复 上下关系8
🙂c++ help.
🙂多谢各位,逐篇花,网上也说了两个解决方案 1 spin 字207 2006-10-12 06:14:04
🙂大致上是这么回事吧 1 随园过客 字127 2006-10-11 23:03:49
🙂很久没碰这个了 1 懒厨 字574 2006-10-11 22:18:18
🙂您说的不对。请进----------- 2 觉昌安塔克世 字330 2006-10-11 22:29:07