Gcc Error Cannot Bind Packed Field
due to spam. Bug36566 - Cannot bind packed field Summary: Cannot bind packed field Status: UNCONFIRMED Alias: None Product: gcc Classification: Unclassified Component: c++ (show other bugs) Version: 4.2.1 Importance: P3 normal Target Milestone: --- Assignee: Not yet assigned to anyone URL: Keywords: Depends on: Blocks: Reported: 2008-06-18 18:28 UTC by Nevin Liber Modified: 2015-03-18 01:55 UTC (History) CC List: 7 users (show) fang gabriel gcc-bugs nevin sowmya_m structurechart xiaoj See Also: Host: Target: Build: Known to work: Known to fail: Last reconfirmed: Attachments Add an attachment (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description Nevin Liber 2008-06-18 18:28:05 UTC If I have a packed struct and try to pass a member variable by reference to a function call, I get the "error: cannot bind packed field" message. If I explicitly create a reference to the member variable first and pass that, things work fine. One of these behaviors must be incorrect. This issue also exists under gcc 4.0.1 (same host/target/build triplet as above) and gcc 4.1.2 under Linux. Under gcc 3.3.3 (on Linux), there was no error. Here is code which demonstrates the issue: struct Squeeze { short s; } __attribute__((aligned(1), packed)); void VerticallyChallenged(short&) {} int main() { Squeeze oj; short& pit(oj.s); VerticallyChallenged(pit); // okay VerticallyChallenged(oj.s); // cannot bind packed field ‘oj.Squeeze::s’ to ‘short int&’ } Comment 1 Andrew Pinski 2008-06-18 18:31:07 UTC This is correct you cannot take the address of a field of a packed struct. > short& pit(oj.s); This should be also an error. Comment 2 Nevin Liber 2008-06-18 18:49:11 UTC Why is this an error (I couldn't find anything in the documentation)? Also, if pointers are used instead of references, should that be an error (currently that compiles just fine)? Comment 3 Nevin Liber 2008-06-18 19:06:01 UTC Expanding on my last comment: which lines in the following code should fail to compile: struct Squeeze { short s; } __attribute__((aligned(1)
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36566 them; it only takes a minute: Sign up Passing reference of packed struct member to template. gcc bug? up vote 1 down vote favorite 2 I encountered a problem, passing struct member to a template function. The function's goal is to take the address and size of the member. Here is simple example: This is the struct. It has http://stackoverflow.com/questions/29340160/passing-reference-of-packed-struct-member-to-template-gcc-bug packed attribute. struct TestStruct { unsigned char elem1; unsigned char elem2; uint64_t elem3; char buf[10000]; int elem4; unsigned char elem5; } __attribute__ ((packed)); this is the template function, which should get a member's address template
CommunitiesAVR FreaksAtmel SMART ARM-based MCUsInternet of ThingsCapacitive TouchProjectsVendorsWiki You are hereHome » Communities » AVR Freaks » Forums » Tools http://www.avrfreaks.net/forum/cannot-bind-packed-field-error » Compilers and General Programming » "cannot bind packed field" error Main menu mobile Home Communities Forums Projects Vendors Wiki Search My summary Privacy Contact Site Use Terms Cookies Communities Forums Projects Vendors WIKI "cannot bind packed field" error Log in or register to post comments Go To Last Post 4 posts / 0 new gcc error Author Message totenhose Level: New Member Joined: Sun. Mar 14, 2004 Posts: 10 View posts #1 Posted by totenhose: Tue. Nov 7, 2006 - 10:42 PM Fivestar widget 12345Total votes: 0 Hi, I get this error message when compiling attached file and same kind of code in my project with avr-gcc: main.cpp: In member function gcc error cannot `void CMyClass::test()': main.cpp:22: error: cannot bind packed field `((CMyClass*)this)->CMyClass::cText ' to `char*&' make: *** [obj/main.o] Error 1 I can't figure out the problem. Google gives some mailing-list topics where dudes try to use "__attribute__ ((packed))" params, but in this case, there isn't such things. This code compiles ok with Dev-Cpp, so i think it's the avr-gcc idiomatique. Anyone have an idea ? Attachment(s): main.cpp Tags:Tools, Compilers and General Programming Log in / register to post comments Top totenhose Level: New Member Joined: Sun. Mar 14, 2004 Posts: 10 View posts #2 Posted by totenhose: Wed. Nov 8, 2006 - 01:05 PM 12345Total votes: 0 Same code in post here: #include