淘客熙熙

主题:c++ help. -- spin

共:💬12 🌺12 新:
全看分页树展 · 主题
家园 c++ help.

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. */

关键词(Tags): #gcc#packed
全看分页树展 · 主题


有趣有益,互惠互利;开阔视野,博采众长。
虚拟的网络,真实的人。天南地北客,相逢皆朋友

Copyright © cchere 西西河