What are the other methods for compiling C ++ errors in __attribute __ ((__ is __))?

when I compiled the following code:

#include <sys/time.h>
#include <stdio.h>

struct TupleHeader {
    timeval     tuple_stime; // 34..37
}__attribute__((__packed__));

 void set_value(timeval& stime){ 
}

int main(){
    TupleHeader tuple;
    set_value(tuple.tuple_stime);
    return 0;
}

I got an error in g++-3.4.2and g++-4.8.3:

attribute-1.cc: In function `int main()':
attribute-1.cc:13: error: cannot bind packed field `tuple.TupleHeader::tuple_stime' to `timeval&'

After I defined timevalmyself as follows and changed everything timevalsin the above code to timeval2:

struct timeval2
{
  __time_t tv_sec;
  __suseconds_t tv_usec;
}__attribute__((__packed__));

the error has disappeared, but I do not want to define a structure that already exists in <bits/time.h>. What are other methods to fix this error? Many thanks!

+4
source share
1 answer

, . , timeval , : , . (FWIW, , , tv_usec !)

, , , - - , char tuple_stime[sizeof(timeval)] . ( .)

+2

All Articles