<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, May 2, 2021, 2:01 PM Sebastian Huber <<a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-brains.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Flexible array members must not appear in the middle of a structure.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Any idea why this doesn't generate a warning? I thought this restriction is well known.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
 cpukit/include/rtems/test.h           | 18 +++++++++-------<br>
 cpukit/libtest/t-test-thread-switch.c | 24 ++++++++++-----------<br>
 testsuites/libtests/ttest02/init.c    | 30 +++++++++++++--------------<br>
 3 files changed, 37 insertions(+), 35 deletions(-)<br>
<br>
diff --git a/cpukit/include/rtems/test.h b/cpukit/include/rtems/test.h<br>
index 10ff665107..f95433bc7c 100644<br>
--- a/cpukit/include/rtems/test.h<br>
+++ b/cpukit/include/rtems/test.h<br>
@@ -89,10 +89,8 @@ typedef struct T_fixture_node {<br>
<br>
 #if defined(__GNUC__) || __STDC_VERSION__ >= 199409L<br>
 #define T_ZERO_LENGTH_ARRAY<br>
-#define T_ZERO_LENGTH_ARRAY_EXTENSION(n) (n)<br>
 #else<br>
 #define T_ZERO_LENGTH_ARRAY 1<br>
-#define T_ZERO_LENGTH_ARRAY_EXTENSION(n) ((n) - 1)<br>
 #endif<br>
<br>
 /** @} */<br>
@@ -2434,22 +2432,26 @@ typedef struct {<br>
        size_t recorded;<br>
        size_t capacity;<br>
        uint64_t switches;<br>
+} T_thread_switch_header;<br>
+<br>
+typedef struct {<br>
+       T_thread_switch_header header;<br>
        T_thread_switch_event events[T_ZERO_LENGTH_ARRAY];<br>
 } T_thread_switch_log;<br>
<br>
 typedef struct {<br>
-       T_thread_switch_log log;<br>
-       T_thread_switch_event events[T_ZERO_LENGTH_ARRAY_EXTENSION(2)];<br>
+       T_thread_switch_header header;<br>
+       T_thread_switch_event events[2];<br>
 } T_thread_switch_log_2;<br>
<br>
 typedef struct {<br>
-       T_thread_switch_log log;<br>
-       T_thread_switch_event events[T_ZERO_LENGTH_ARRAY_EXTENSION(4)];<br>
+       T_thread_switch_header header;<br>
+       T_thread_switch_event events[4];<br>
 } T_thread_switch_log_4;<br>
<br>
 typedef struct {<br>
-       T_thread_switch_log log;<br>
-       T_thread_switch_event events[T_ZERO_LENGTH_ARRAY_EXTENSION(10)];<br>
+       T_thread_switch_header header;<br>
+       T_thread_switch_event events[10];<br>
 } T_thread_switch_log_10;<br>
<br>
 T_thread_switch_log *T_thread_switch_record(T_thread_switch_log *);<br>
diff --git a/cpukit/libtest/t-test-thread-switch.c b/cpukit/libtest/t-test-thread-switch.c<br>
index 87ad4651fc..60179aaa40 100644<br>
--- a/cpukit/libtest/t-test-thread-switch.c<br>
+++ b/cpukit/libtest/t-test-thread-switch.c<br>
@@ -96,11 +96,11 @@ T_thread_switch_recorder(Thread_Control *executing, Thread_Control *heir)<br>
        if (log != NULL) {<br>
                size_t recorded;<br>
<br>
-               ++log->switches;<br>
-               recorded = log->recorded;<br>
+               ++log->header.switches;<br>
+               recorded = log->header.recorded;<br>
<br>
-               if (recorded < log->capacity) {<br>
-                       log->recorded = recorded + 1;<br>
+               if (recorded < log->header.capacity) {<br>
+                       log->header.recorded = recorded + 1;<br>
                        log->events[recorded].executing = executing->Object.id;<br>
                        log->events[recorded].heir = heir->Object.id;<br>
                        log->events[recorded].cpu =<br>
@@ -127,8 +127,8 @@ T_thread_switch_record(T_thread_switch_log *log)<br>
        }<br>
<br>
        if (log != NULL) {<br>
-               log->recorded = 0;<br>
-               log->switches = 0;<br>
+               log->header.recorded = 0;<br>
+               log->header.switches = 0;<br>
        }<br>
<br>
        rtems_interrupt_lock_acquire(&ctx->lock, &lock_context);<br>
@@ -142,20 +142,20 @@ T_thread_switch_record(T_thread_switch_log *log)<br>
 T_thread_switch_log *<br>
 T_thread_switch_record_2(T_thread_switch_log_2 *log)<br>
 {<br>
-       log->log.capacity = 2;<br>
-       return T_thread_switch_record(&log->log);<br>
+       log->header.capacity = T_ARRAY_SIZE(log->events);<br>
+       return T_thread_switch_record((T_thread_switch_log *)log);<br>
 }<br>
<br>
 T_thread_switch_log *<br>
 T_thread_switch_record_4(T_thread_switch_log_4 *log)<br>
 {<br>
-       log->log.capacity = 4;<br>
-       return T_thread_switch_record(&log->log);<br>
+       log->header.capacity = T_ARRAY_SIZE(log->events);<br>
+       return T_thread_switch_record((T_thread_switch_log *)log);<br>
 }<br>
<br>
 T_thread_switch_log *<br>
 T_thread_switch_record_10(T_thread_switch_log_10 *log)<br>
 {<br>
-       log->log.capacity = 10;<br>
-       return T_thread_switch_record(&log->log);<br>
+       log->header.capacity = T_ARRAY_SIZE(log->events);<br>
+       return T_thread_switch_record((T_thread_switch_log *)log);<br>
 }<br>
diff --git a/testsuites/libtests/ttest02/init.c b/testsuites/libtests/ttest02/init.c<br>
index 7f972aec7e..4d540c9a86 100644<br>
--- a/testsuites/libtests/ttest02/init.c<br>
+++ b/testsuites/libtests/ttest02/init.c<br>
@@ -222,23 +222,23 @@ T_TEST_CASE(TestThreadSwitch)<br>
        memset(&log_2, 0xff, sizeof(log_2));<br>
        log = T_thread_switch_record_2(&log_2);<br>
        T_null(log);<br>
-       T_eq_sz(log_2.log.recorded, 0);<br>
-       T_eq_sz(log_2.log.capacity, 2);<br>
-       T_eq_u64(log_2.log.switches, 0);<br>
+       T_eq_sz(log_2.header.recorded, 0);<br>
+       T_eq_sz(log_2.header.capacity, 2);<br>
+       T_eq_u64(log_2.header.switches, 0);<br>
<br>
        memset(&log_4, 0xff, sizeof(log_4));<br>
        log = T_thread_switch_record_4(&log_4);<br>
-       T_eq_ptr(log, &log_2.log);<br>
-       T_eq_sz(log_4.log.recorded, 0);<br>
-       T_eq_sz(log_4.log.capacity, 4);<br>
-       T_eq_u64(log_4.log.switches, 0);<br>
+       T_eq_ptr(&log->header, &log_2.header);<br>
+       T_eq_sz(log_4.header.recorded, 0);<br>
+       T_eq_sz(log_4.header.capacity, 4);<br>
+       T_eq_u64(log_4.header.switches, 0);<br>
<br>
        memset(&log_10, 0xff, sizeof(log_10));<br>
        log = T_thread_switch_record_10(&log_10);<br>
-       T_eq_ptr(log, &log_4.log);<br>
-       T_eq_sz(log_10.log.recorded, 0);<br>
-       T_eq_sz(log_10.log.capacity, 10);<br>
-       T_eq_u64(log_10.log.switches, 0);<br>
+       T_eq_ptr(&log->header, &log_4.header);<br>
+       T_eq_sz(log_10.header.recorded, 0);<br>
+       T_eq_sz(log_10.header.capacity, 10);<br>
+       T_eq_u64(log_10.header.switches, 0);<br>
<br>
        for (i = 0; i < 6; ++i) {<br>
                rtems_status_code sc;<br>
@@ -248,10 +248,10 @@ T_TEST_CASE(TestThreadSwitch)<br>
        }<br>
<br>
        log = T_thread_switch_record(NULL);<br>
-       T_eq_ptr(log, &log_10.log);<br>
-       T_eq_sz(log->recorded, 10);<br>
-       T_eq_sz(log->capacity, 10);<br>
-       T_eq_u64(log->switches, 12);<br>
+       T_eq_ptr(&log->header, &log_10.header);<br>
+       T_eq_sz(log->header.recorded, 10);<br>
+       T_eq_sz(log->header.capacity, 10);<br>
+       T_eq_u64(log->header.switches, 12);<br>
        executing = rtems_task_self();<br>
        T_eq_u32(log->events[0].executing, executing);<br>
        T_ne_u32(log->events[0].heir, 0);<br>
-- <br>
2.26.2<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank" rel="noreferrer">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div></div>