From 3d78ceb0abc4db48d884008171042c5651b80aab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marvin=20Ha=CC=88user?= <mhaeuser@posteo.de>
Date: Sat, 25 Nov 2023 20:37:24 +0100
Subject: [PATCH] simulator: emit channels array only when not empty

Arrays of length 0 yield implementation-defined behaviour, which causes
a compiler warning. In C, this was typically used to model
flexibly-sized array members trailing a struct. Here, length 0 actually
means it occupies no storage.

Hence, do not emit the _channels array when it would otherwise have a
length of 0.
---
 .../tmltranslator/tomappingsystemc2/MappedSystemCTask.java   | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/main/java/tmltranslator/tomappingsystemc2/MappedSystemCTask.java b/src/main/java/tmltranslator/tomappingsystemc2/MappedSystemCTask.java
index 0c0d7a9d1b..3633305b04 100644
--- a/src/main/java/tmltranslator/tomappingsystemc2/MappedSystemCTask.java
+++ b/src/main/java/tmltranslator/tomappingsystemc2/MappedSystemCTask.java
@@ -1131,7 +1131,10 @@ public class MappedSystemCTask {
         //code += "ParamType arg2__req" + SCCR;
         //code += "ParamType arg3__req" + SCCR;
         code += "ParamType rnd__0" + SCCR;
-        code += "TMLChannel* _channels[" + (channels.size() + events.size() + (task.isRequested() ? 1 : 0)) + "]" + SCCR;
+        int num = channels.size() + events.size() + (task.isRequested() ? 1 : 0);
+        if (num > 0) {
+          code += "TMLChannel* _channels[" + num + "]" + SCCR;
+        }
         return code;
     }
 
-- 
GitLab