nkjnm
Dependencies: MAX44000 nexpaq_mdk
Fork of LED_Demo by
mbd_os/TESTS/mbedmicro-mbed/attributes/attributes.c@1:55a6170b404f, 2016-09-17 (annotated)
- Committer:
- nexpaq
- Date:
- Sat Sep 17 16:32:05 2016 +0000
- Revision:
- 1:55a6170b404f
checking in for sharing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 1:55a6170b404f | 1 | #include "toolchain.h" |
nexpaq | 1:55a6170b404f | 2 | |
nexpaq | 1:55a6170b404f | 3 | #include <stdio.h> |
nexpaq | 1:55a6170b404f | 4 | #include <stdint.h> |
nexpaq | 1:55a6170b404f | 5 | |
nexpaq | 1:55a6170b404f | 6 | |
nexpaq | 1:55a6170b404f | 7 | MBED_PACKED(struct) TestAttrPackedStruct1 { |
nexpaq | 1:55a6170b404f | 8 | char a; |
nexpaq | 1:55a6170b404f | 9 | int x; |
nexpaq | 1:55a6170b404f | 10 | }; |
nexpaq | 1:55a6170b404f | 11 | |
nexpaq | 1:55a6170b404f | 12 | typedef MBED_PACKED(struct) { |
nexpaq | 1:55a6170b404f | 13 | char a; |
nexpaq | 1:55a6170b404f | 14 | int x; |
nexpaq | 1:55a6170b404f | 15 | } TestAttrPackedStruct2; |
nexpaq | 1:55a6170b404f | 16 | |
nexpaq | 1:55a6170b404f | 17 | int testPacked() { |
nexpaq | 1:55a6170b404f | 18 | int failed = 0; |
nexpaq | 1:55a6170b404f | 19 | |
nexpaq | 1:55a6170b404f | 20 | if (sizeof(struct TestAttrPackedStruct1) != sizeof(int) + sizeof(char)) { |
nexpaq | 1:55a6170b404f | 21 | failed++; |
nexpaq | 1:55a6170b404f | 22 | } |
nexpaq | 1:55a6170b404f | 23 | |
nexpaq | 1:55a6170b404f | 24 | if (sizeof(TestAttrPackedStruct2) != sizeof(int) + sizeof(char)) { |
nexpaq | 1:55a6170b404f | 25 | failed++; |
nexpaq | 1:55a6170b404f | 26 | } |
nexpaq | 1:55a6170b404f | 27 | |
nexpaq | 1:55a6170b404f | 28 | return failed; |
nexpaq | 1:55a6170b404f | 29 | } |
nexpaq | 1:55a6170b404f | 30 | |
nexpaq | 1:55a6170b404f | 31 | |
nexpaq | 1:55a6170b404f | 32 | MBED_ALIGN(8) char a; |
nexpaq | 1:55a6170b404f | 33 | MBED_ALIGN(8) char b; |
nexpaq | 1:55a6170b404f | 34 | MBED_ALIGN(16) char c; |
nexpaq | 1:55a6170b404f | 35 | MBED_ALIGN(8) char d; |
nexpaq | 1:55a6170b404f | 36 | MBED_ALIGN(16) char e; |
nexpaq | 1:55a6170b404f | 37 | |
nexpaq | 1:55a6170b404f | 38 | int testAlign() { |
nexpaq | 1:55a6170b404f | 39 | int failed = 0; |
nexpaq | 1:55a6170b404f | 40 | |
nexpaq | 1:55a6170b404f | 41 | if(((uintptr_t)&a) & 0x7){ |
nexpaq | 1:55a6170b404f | 42 | failed++; |
nexpaq | 1:55a6170b404f | 43 | } |
nexpaq | 1:55a6170b404f | 44 | if(((uintptr_t)&b) & 0x7){ |
nexpaq | 1:55a6170b404f | 45 | failed++; |
nexpaq | 1:55a6170b404f | 46 | } |
nexpaq | 1:55a6170b404f | 47 | if(((uintptr_t)&c) & 0xf){ |
nexpaq | 1:55a6170b404f | 48 | failed++; |
nexpaq | 1:55a6170b404f | 49 | } |
nexpaq | 1:55a6170b404f | 50 | if(((uintptr_t)&d) & 0x7){ |
nexpaq | 1:55a6170b404f | 51 | failed++; |
nexpaq | 1:55a6170b404f | 52 | } |
nexpaq | 1:55a6170b404f | 53 | if(((uintptr_t)&e) & 0xf){ |
nexpaq | 1:55a6170b404f | 54 | failed++; |
nexpaq | 1:55a6170b404f | 55 | } |
nexpaq | 1:55a6170b404f | 56 | |
nexpaq | 1:55a6170b404f | 57 | return failed; |
nexpaq | 1:55a6170b404f | 58 | } |
nexpaq | 1:55a6170b404f | 59 | |
nexpaq | 1:55a6170b404f | 60 | |
nexpaq | 1:55a6170b404f | 61 | int testUnused1(MBED_UNUSED int arg) { |
nexpaq | 1:55a6170b404f | 62 | return 0; |
nexpaq | 1:55a6170b404f | 63 | } |
nexpaq | 1:55a6170b404f | 64 | |
nexpaq | 1:55a6170b404f | 65 | int testUnused() { |
nexpaq | 1:55a6170b404f | 66 | return testUnused1(0); |
nexpaq | 1:55a6170b404f | 67 | } |
nexpaq | 1:55a6170b404f | 68 | |
nexpaq | 1:55a6170b404f | 69 | |
nexpaq | 1:55a6170b404f | 70 | int testWeak1(); |
nexpaq | 1:55a6170b404f | 71 | int testWeak2(); |
nexpaq | 1:55a6170b404f | 72 | |
nexpaq | 1:55a6170b404f | 73 | MBED_WEAK int testWeak1() { |
nexpaq | 1:55a6170b404f | 74 | return 1; |
nexpaq | 1:55a6170b404f | 75 | } |
nexpaq | 1:55a6170b404f | 76 | |
nexpaq | 1:55a6170b404f | 77 | int testWeak2() { |
nexpaq | 1:55a6170b404f | 78 | return 0; |
nexpaq | 1:55a6170b404f | 79 | } |
nexpaq | 1:55a6170b404f | 80 | |
nexpaq | 1:55a6170b404f | 81 | int testWeak() { |
nexpaq | 1:55a6170b404f | 82 | return testWeak1() | testWeak2(); |
nexpaq | 1:55a6170b404f | 83 | } |
nexpaq | 1:55a6170b404f | 84 | |
nexpaq | 1:55a6170b404f | 85 | |
nexpaq | 1:55a6170b404f | 86 | MBED_PURE int testPure1() { |
nexpaq | 1:55a6170b404f | 87 | return 0; |
nexpaq | 1:55a6170b404f | 88 | } |
nexpaq | 1:55a6170b404f | 89 | |
nexpaq | 1:55a6170b404f | 90 | int testPure() { |
nexpaq | 1:55a6170b404f | 91 | return testPure1(); |
nexpaq | 1:55a6170b404f | 92 | } |
nexpaq | 1:55a6170b404f | 93 | |
nexpaq | 1:55a6170b404f | 94 | |
nexpaq | 1:55a6170b404f | 95 | MBED_FORCEINLINE int testForceInline1() { |
nexpaq | 1:55a6170b404f | 96 | return 0; |
nexpaq | 1:55a6170b404f | 97 | } |
nexpaq | 1:55a6170b404f | 98 | |
nexpaq | 1:55a6170b404f | 99 | int testForceInline() { |
nexpaq | 1:55a6170b404f | 100 | return testForceInline1(); |
nexpaq | 1:55a6170b404f | 101 | } |
nexpaq | 1:55a6170b404f | 102 | |
nexpaq | 1:55a6170b404f | 103 | |
nexpaq | 1:55a6170b404f | 104 | MBED_NORETURN int testNoReturn1() { |
nexpaq | 1:55a6170b404f | 105 | while (1) {} |
nexpaq | 1:55a6170b404f | 106 | } |
nexpaq | 1:55a6170b404f | 107 | |
nexpaq | 1:55a6170b404f | 108 | int testNoReturn() { |
nexpaq | 1:55a6170b404f | 109 | if (0) { |
nexpaq | 1:55a6170b404f | 110 | testNoReturn1(); |
nexpaq | 1:55a6170b404f | 111 | } |
nexpaq | 1:55a6170b404f | 112 | return 0; |
nexpaq | 1:55a6170b404f | 113 | } |
nexpaq | 1:55a6170b404f | 114 | |
nexpaq | 1:55a6170b404f | 115 | |
nexpaq | 1:55a6170b404f | 116 | int testUnreachable1(int i) { |
nexpaq | 1:55a6170b404f | 117 | switch (i) { |
nexpaq | 1:55a6170b404f | 118 | case 0: |
nexpaq | 1:55a6170b404f | 119 | return 0; |
nexpaq | 1:55a6170b404f | 120 | } |
nexpaq | 1:55a6170b404f | 121 | |
nexpaq | 1:55a6170b404f | 122 | MBED_UNREACHABLE; |
nexpaq | 1:55a6170b404f | 123 | } |
nexpaq | 1:55a6170b404f | 124 | |
nexpaq | 1:55a6170b404f | 125 | int testUnreachable() { |
nexpaq | 1:55a6170b404f | 126 | return testUnreachable1(0); |
nexpaq | 1:55a6170b404f | 127 | } |
nexpaq | 1:55a6170b404f | 128 | |
nexpaq | 1:55a6170b404f | 129 | |
nexpaq | 1:55a6170b404f | 130 | MBED_DEPRECATED("this message should not be displayed") |
nexpaq | 1:55a6170b404f | 131 | void testDeprecatedUnused(); |
nexpaq | 1:55a6170b404f | 132 | void testDeprecatedUnused() { } |
nexpaq | 1:55a6170b404f | 133 | |
nexpaq | 1:55a6170b404f | 134 | MBED_DEPRECATED("this message should be displayed") |
nexpaq | 1:55a6170b404f | 135 | int testDeprecatedUsed(); |
nexpaq | 1:55a6170b404f | 136 | int testDeprecatedUsed() { |
nexpaq | 1:55a6170b404f | 137 | return 0; |
nexpaq | 1:55a6170b404f | 138 | } |
nexpaq | 1:55a6170b404f | 139 | |
nexpaq | 1:55a6170b404f | 140 | MBED_DEPRECATED_SINCE("mbed-os-3.14", "this message should not be displayed") |
nexpaq | 1:55a6170b404f | 141 | void testDeprecatedSinceUnused(); |
nexpaq | 1:55a6170b404f | 142 | void testDeprecatedSinceUnused() { } |
nexpaq | 1:55a6170b404f | 143 | |
nexpaq | 1:55a6170b404f | 144 | MBED_DEPRECATED_SINCE("mbed-os-3.14", "this message should be displayed") |
nexpaq | 1:55a6170b404f | 145 | int testDeprecatedSinceUsed(); |
nexpaq | 1:55a6170b404f | 146 | int testDeprecatedSinceUsed() { |
nexpaq | 1:55a6170b404f | 147 | return 0; |
nexpaq | 1:55a6170b404f | 148 | } |
nexpaq | 1:55a6170b404f | 149 | |
nexpaq | 1:55a6170b404f | 150 | int testDeprecated() { |
nexpaq | 1:55a6170b404f | 151 | return testDeprecatedUsed() + testDeprecatedSinceUsed(); |
nexpaq | 1:55a6170b404f | 152 | } |
nexpaq | 1:55a6170b404f | 153 |