Skip to content

Commit d8db49c

Browse files
GuEe-GUIRbb666
authored andcommitted
[COMPILER/FEATURE] Support rt_packed
__ARMCC_VERSION: https://smtp.keil.com/support/man/docs/armcc/armcc_chr1359124980173.htm __IAR_SYSTEMS_ICC__: <Not Found> __GNUC__: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute __ADSPBLACKFIN__: <Not Found> _MSC_VER: https://learn.microsoft.com/en-us/cpp/preprocessor/pack?view=msvc-170 __TI_COMPILER_VERSION__: https://software-dl.ti.com/codegen/docs/tiarmclang/rel1_3_0_LTS/migration_guide/migrating_c_and_cpp_source/pragmas_and_attributes.html __TASKING__: https://resources.tasking.com/sites/default/files/2021-02/TASKING_Alignment%20Requirements%20Restrictions_WEB.pdf Usage: ```c rt_packed(struct object1 { int dword; char byte; }); typedef struct object1 object1; rt_packed(struct object2 { int dword; char byte; }); ``` Signed-off-by: GuEe-GUI <[email protected]>
1 parent a573ea0 commit d8db49c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

include/rtcompiler.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#define rt_section(x) __attribute__((section(x)))
1717
#define rt_used __attribute__((used))
1818
#define rt_align(n) __attribute__((aligned(n)))
19+
#if __ARMCC_VERSION >= 6010050
20+
#define rt_packed(declare) declare __attribute__((packed))
21+
#else
22+
#define rt_packed(declare) declare
23+
#endif
1924
#define rt_weak __attribute__((weak))
2025
#define rt_typeof typeof
2126
#define rt_noreturn
@@ -26,6 +31,7 @@
2631
#define rt_used __root
2732
#define PRAGMA(x) _Pragma(#x)
2833
#define rt_align(n) PRAGMA(data_alignment=n)
34+
#define rt_packed(declare) declare
2935
#define rt_weak __weak
3036
#define rt_typeof __typeof
3137
#define rt_noreturn
@@ -37,6 +43,7 @@
3743
#define rt_section(x) __attribute__((section(x)))
3844
#define rt_used __attribute__((used))
3945
#define rt_align(n) __attribute__((aligned(n)))
46+
#define rt_packed(declare) declare __attribute__((packed))
4047
#define rt_weak __attribute__((weak))
4148
#define rt_typeof __typeof__
4249
#define rt_noreturn __attribute__ ((noreturn))
@@ -46,6 +53,7 @@
4653
#define rt_section(x) __attribute__((section(x)))
4754
#define rt_used __attribute__((used))
4855
#define rt_align(n) __attribute__((aligned(n)))
56+
#define rt_packed(declare) declare
4957
#define rt_weak __attribute__((weak))
5058
#define rt_typeof typeof
5159
#define rt_noreturn
@@ -55,6 +63,7 @@
5563
#define rt_section(x)
5664
#define rt_used
5765
#define rt_align(n) __declspec(align(n))
66+
#define rt_packed(declare) __pragma(pack(push, 1)) declare __pragma(pack(pop))
5867
#define rt_weak
5968
#define rt_typeof typeof
6069
#define rt_noreturn
@@ -74,6 +83,7 @@
7483
#endif
7584
#define PRAGMA(x) _Pragma(#x)
7685
#define rt_align(n) __attribute__((aligned(n)))
86+
#define rt_packed(declare) declare __attribute__((packed))
7787
#ifdef __TI_EABI__
7888
#define rt_weak __attribute__((weak))
7989
#else
@@ -88,6 +98,7 @@
8898
#define rt_used __attribute__((used, protect))
8999
#define PRAGMA(x) _Pragma(#x)
90100
#define rt_align(n) __attribute__((__align(n)))
101+
#define rt_packed(declare) declare __packed__
91102
#define rt_weak __attribute__((weak))
92103
#define rt_typeof typeof
93104
#define rt_noreturn

0 commit comments

Comments
 (0)