This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with GCC 3.4 vs 3.3 and packed structs


The following code snippet works as expected in GCC 3.3.3 (both i686 and x86_64 platforms), but fails with a compile error on GCC 3.4:

     #define PACKED __attribute__ ((packed))
                                                                                
     struct three 
     {
        char  larry;
        char  curly;
        char  moe;
     } PACKED *stooges;
                                                                                
     char & knucklehead(void)
     {
         return stooges->moe;
     }

The compile error is: 
   packed.c: In function `char& knucklehead()':
   packed.c:12: error: cannot bind packed field `stooges->three::moe' to `char&'

I searched through the GCC message archives and did run across a series of messages that state that fields in packed structures are now treated as if they are bitfields and taking the address of (or reference of) the fields is not supported.  Unfortunately, our application relies heavily on packed structures and uses the above construct frequently. 

I have tried moving the PACKED attribute to the individual fields, or after "three", as well as applying it to the referenc of knucklehead, but all to no avail.   Is there any work around - either via a compiler option, or a change to our source code (other than removing the packed attribute) that you can recommend?

Similarly, I read through the information in the GCC 3.4.1 manual on the use of the packed attribute and tried the following sequence of code taken straight from the manual:

     struct my_unpacked_struct
     {
        char c;
        int i;
     };
                                                                                
     struct my_packed_struct __attribute__ ((__packed__))
     {
        char c;
        int  i;
        struct my_unpacked_struct s;
     };
                                                                                
This code also fails to compile, but with a different message:

   packed.c:9: error: expected unqualified-id before '{' token
   packed.c:9: error: expected `,' or `;' before '{' token

Any assistance, or advice, is greatly appreciated.
Thanx.

PS: This email address is protected via Earthlink's spamBlocker, so any sender will receive an email message pointing them to a webpage where they must first request to be added to my approved list before the email can be delivered.  I check the 'spam folder' regularly, but occasionally miss a real message, so I apologize for the inconvenience, but I request that you please follow through the simple steps to make sure the email is sent on to me.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]