unaligned data에 대한 atomic operation의 동작을 확인하기 위해 unaligned data를 만들어야 되었는데, 방법을 몰라 헤매이다,. __attribute__ (packed)를 쓰면 된다는 것을 알게 되었다. 

packed
Found in versions: 2.7-3.4
Description:
     This attribute, attached to `struct' or `union' type definition,
     specifies that each member of the structure or union is placed to
     minimize the memory required. When attached to an `enum'
     definition, it indicates that the smallest integral type should be
     used.

     Specifying this attribute for `struct' and `union' types is
     equivalent to specifying the `packed' attribute on each of the
     structure or union members.  Specifying the `-fshort-enums' flag
     on the line is equivalent to specifying the `packed' attribute on
     all `enum' definitions.

     In the following example `struct my_packed_struct''s members are
     packed closely together, but the internal layout of its `s' member
     is not packed - to do that, `struct my_unpacked_struct' would need
     to be packed too.

          struct my_unpacked_struct
           {
              char c;
              int i;
           };
          
          struct my_packed_struct __attribute__ ((__packed__))
            {
               char c;
               int  i;
               struct my_unpacked_struct s;
            };

     You may only specify this attribute on the definition of a `enum',
     `struct' or `union', not on a `typedef' which does not also define
     the enumerated type, structure or union.





http://ohse.de/uwe/articles/gcc-attributes.html#type-packed

'프로그래밍언어' 카테고리의 다른 글

JAVA GC에 대한 좋은 글들  (0) 2013.05.02
mutable  (0) 2013.03.26
__attribute__ (packed) : 구조체 정렬  (0) 2013.03.20
각 언어별 데이터 표현 범위 비교  (0) 2013.01.11
OLTP vs OLAP  (0) 2012.11.15
Java Collection 구조 설명  (0) 2012.11.03
Posted by 라판