diff --git a/database/DBtcontact.c b/database/DBtcontact.c index 3a6b1fb0..9a6ef3eb 100644 --- a/database/DBtcontact.c +++ b/database/DBtcontact.c @@ -953,24 +953,22 @@ DBFullResidueMask(type, rmask) TileType type; TileTypeBitMask *rmask; { - TileType t; - TileTypeBitMask *lmask; - LayerInfo *li, *lr; - - li = &dbLayerInfo[type]; - lmask = &li->l_residues; - TTMaskZero(rmask); + LayerInfo *li = &dbLayerInfo[type]; + const TileTypeBitMask *lmask = &li->l_residues; if (type < DBNumUserLayers) { - TTMaskSetMask(rmask, &li->l_residues); + TTMaskCopy(rmask, lmask); } else { - for (t = TT_TECHDEPBASE; t < DBNumUserLayers; t++) + TileType t; + const int tt_last = DBNumUserLayers; + TTMaskZero(rmask); + for (t = TT_TECHDEPBASE; t < tt_last; t++) if (TTMaskHasType(lmask, t)) { - lr = &dbLayerInfo[t]; + LayerInfo *lr = &dbLayerInfo[t]; TTMaskSetMask(rmask, &lr->l_residues); } } diff --git a/database/database.h.in b/database/database.h.in index 6801a7cd..eaa9ff97 100644 --- a/database/database.h.in +++ b/database/database.h.in @@ -877,7 +877,7 @@ extern TileType DBTechFindStacking(); extern bool DBIsContact(); extern PlaneMask DBLayerPlanes(); -extern TileTypeBitMask *DBResidueMask(); +extern __nodiscard__ TileTypeBitMask *DBResidueMask(TileType type); extern void DBFullResidueMask(); /* Miscellaneous */ diff --git a/scripts/makedbh.in b/scripts/makedbh.in index 83ccaaef..64eb6738 100755 --- a/scripts/makedbh.in +++ b/scripts/makedbh.in @@ -51,6 +51,10 @@ add_generated_mask_macro( "TTMaskZero(m)", "(m)->tt_words[{i}] = 0", ) +add_generated_mask_macro( + "TTMaskCopy(m, n)", + "(m)->tt_words[{i}] = (n)->tt_words[{i}]", +) add_generated_mask_macro( "TTMaskIsZero(m)", "(m)->tt_words[{i}] == 0", diff --git a/utils/magic.h b/utils/magic.h index ded4bf1c..25043c46 100644 --- a/utils/magic.h +++ b/utils/magic.h @@ -194,6 +194,21 @@ extern char AbortMessage[]; /* looking to squash excessive -Wpedantic warnings ? add into defs.mak: CPPFLAGS += -Wno-variadic-macros */ #define ANALYSER_NONNULL(n...) __attribute__((nonnull(n))) #define ANALYSER_RETURNS_NONNULL __attribute__((returns_nonnull)) + + /* These have keyword like behaviour so __nodiscard__ looks more like a keyword and is recognisable as such + * the historic use of __inline__ set a precedent on how backward compatibiliy maybe achieved for such things + */ + +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)) + /* since C23 but maybe some compilers supported it before their official C23 releases */ + #define __nodiscard__ [[nodiscard]] +#elif (defined(__GNUC__) && (__GNUC__ >= 4)) + #define __nodiscard__ __attribute__((warn_unused_result)) +#elif (defined(__clang__) && (__clang_major__ >= 1)) + #define __nodiscard__ __attribute__((warn_unused_result)) +#else + #define __nodiscard__ /* */ +#endif #else #define ATTR_FORMAT_PRINTF_1 /* */ #define ATTR_FORMAT_PRINTF_2 /* */ @@ -207,6 +222,8 @@ extern char AbortMessage[]; #define ANALYSER_MALLOC(dealloc, idx) /* */ #define ANALYSER_NONNULL(n...) /* */ #define ANALYSER_RETURNS_NONNULL /* */ + + #define __nodiscard__ /* */ #endif /* ---------------- Start of Machine Configuration Section ----------------- */