commit 2c6ac85265129adf1ba2d7c30bb743710ec783ef
parent 05ae53a8c3723e8e9b0caf8c45a955097056fa56
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 28 Jan 2026 16:30:10 +0100
Remove a GCC warning on the SHTR_MOLECULE_CSTR table
It warned that the constant was not being used. Note that it was not
necessarily GCC's policy to warn that a static constant was not being
used, as these can be proposed as a correspondence table in a header
file, as is the case here. However, GCC now seems to consider this
practice questionable.
Instead of using a GCC-specific attribute to avoid this warning, a
static function is added to index the mapping table and verify that the
index provided is not out of bounds. The mapping table is therefore no
longer unused and the warning disappears. And this is done without
having to implement this function via a "switch" directive, which would
have unnecessarily bloated the code.
Diffstat:
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/shtr.h b/src/shtr.h
@@ -63,7 +63,7 @@ enum shtr_molecule_id {
};
/* Table that associates the molecule ID with its name */
-static const char* SHTR_MOLECULE_CSTR[SHTR_MAX_MOLECULES_COUNT] = {
+static const char* SHTR_MOLECULE_CSTR__[SHTR_MAX_MOLECULES_COUNT] = {
NULL, /* SHTR_MOLECULE_ID_NULL__ */
"H2O", "CO2", "O3", "N2O", "CO", "CH4",
@@ -78,6 +78,13 @@ static const char* SHTR_MOLECULE_CSTR[SHTR_MAX_MOLECULES_COUNT] = {
"NF3"
};
+static INLINE const char*
+shtr_molecule_cstr(const enum shtr_molecule_id id)
+{
+ ASSERT(id < SHTR_MAX_MOLECULES_COUNT);
+ return SHTR_MOLECULE_CSTR__[id];
+}
+
struct shtr_isotope {
double abundance; /* in ]0, 1] */
double Q296K; /* Partition function at Tref = 296K */