![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I wanto use a packed structure with a malloc. But the pack pragma only applies to data declarations not typdef. is this possible in C/C++? eg I want do something like; #define PACK_UNIX __attribute__((aligned)) #define Iu32 to be a 4 byte variable type. typedef struct thread_trace_element1 { Iu32 timestamp PACK_UNIX ; Iu32 tracepoint PACK_UNIX ; Iu32 type PACK_UNIX ; Iu32 p1 PACK_UNIX ; Iu32 p2 PACK_UNIX ; Iu32 p3 PACK_UNIX ; Iu32 p4 PACK_UNIX ; } thread_trace_element1_t; typedef struct thread_trace_element2 { Iu32 timestamp PACK_UNIX ; Iu32 tracepoint PACK_UNIX ; Iu32 type PACK_UNIX ; Iu32 mode PACK_UNIX ; Iu32 handle PACK_UNIX ; Iu32 rc PACK_UNIX ; Iu32 p4 PACK_UNIX ; } thread_trace_element2_t; typedef union u_thread_trace_element { thread_trace_element1_t; thread_trace_element2_t } u_thread_trace_element_t; and then void *p; p = malloc( sizeof(u_thread_trace_element_t )) so that I can then use thread_trace_element1_t *q; thread_trace_element2_t; *r; q = p; r = p; and then use q->p1 and r->mode to refer to the same 4 byte value |
#3
| |||
| |||
|
|
I wanto use a packed structure with a malloc. But the pack pragma only applies to data declarations not typdef. is this possible in C/C++? eg I want do something like; #define PACK_UNIX __attribute__((aligned)) #define Iu32 to be a 4 byte variable type. typedef struct thread_trace_element1 { Iu32 timestamp PACK_UNIX ; Iu32 tracepoint PACK_UNIX ; Iu32 type PACK_UNIX ; Iu32 p1 PACK_UNIX ; Iu32 p2 PACK_UNIX ; Iu32 p3 PACK_UNIX ; Iu32 p4 PACK_UNIX ; } thread_trace_element1_t; typedef struct thread_trace_element2 { Iu32 timestamp PACK_UNIX ; Iu32 tracepoint PACK_UNIX ; Iu32 type PACK_UNIX ; Iu32 mode PACK_UNIX ; Iu32 handle PACK_UNIX ; Iu32 rc PACK_UNIX ; Iu32 p4 PACK_UNIX ; } thread_trace_element2_t; typedef union u_thread_trace_element { thread_trace_element1_t; thread_trace_element2_t } u_thread_trace_element_t; and then void *p; p = malloc( sizeof(u_thread_trace_element_t )) so that I can then use thread_trace_element1_t *q; thread_trace_element2_t; *r; q = p; r = p; and then use q->p1 and r->mode to refer to the same 4 byte value |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |