* lib/attribute.h (UNNAMED): New macro, like _GL_UNNAMED.
When applicable, prefer this new macro to MAYBE_UNUSED.
+2025-12-24 Paul Eggert <eggert@cs.ucla.edu>
+
+ attribute: new C macro UNNAMED
+ * lib/attribute.h (UNNAMED): New macro, like _GL_UNNAMED.
+ When applicable, prefer this new macro to MAYBE_UNUSED.
+
2025-12-23 Paul Eggert <eggert@cs.ucla.edu>
New C macro _GL_UNNAMED
Also, these exceptional macros should be placed at the start of
function declarations, whereas the @code{ATTRIBUTE_*} macros can be
placed at the end.
+
+The module also defines the macro @code{UNNAMED},
+designed for function parameters that are never used,
+whereas the @code{MAYBE_UNUSED} attribute is better suited for parameters
+that might or might not be unused depending on preprocessor macro settings.
+For example:
+
+@example
+int
+f (int a, MAYBE_UNUSED int b, int UNNAMED (c))
+@{
+ int r = a;
+#ifdef B_FEATURE
+ r |= b;
+#endif
+ return r;
+@}
+@end example
_GL_ATTRIBUTE_NONNULL_IF_NONZERO, _GL_ATTRIBUTE_NONSTRING,
_GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PACKED, _GL_ATTRIBUTE_PURE,
_GL_ATTRIBUTE_REPRODUCIBLE, _GL_ATTRIBUTE_RETURNS_NONNULL,
- _GL_ATTRIBUTE_SENTINEL, _GL_ATTRIBUTE_UNSEQUENCED. */
+ _GL_ATTRIBUTE_SENTINEL, _GL_ATTRIBUTE_UNSEQUENCED, _GL_UNNAMED. */
#if !_GL_CONFIG_H_INCLUDED
#error "Please include config.h first."
#endif
#define ATTRIBUTE_MAY_ALIAS _GL_ATTRIBUTE_MAY_ALIAS
+/* ==================== Unnamed function parameters ======================== */
+
+/* Although UNNAMED is not an attribute, it is related to MAYBE_UNUSED
+ and so is defined here for convenience. */
+
+/* UNNAMED (ID) is the "name" of an unnamed function parameter.
+ Each of the function's unnamed parameters should have a unique "name".
+ The "name" cannot be used. This ports both to C17 and earlier, which
+ lack unnamed parameters, and to C++ and later C, which have them. */
+/* Applies to:
+ - function parameters. */
+#define UNNAMED(id) _GL_UNNAMED (id)
+
+
#endif /* _GL_ATTRIBUTE_H */
specified by ATTR. For variable size bitsets, N_BITS is only a
hint and may be zero. */
enum bitset_type
-bitset_type_choose (MAYBE_UNUSED bitset_bindex n_bits, unsigned attr)
+bitset_type_choose (bitset_bindex UNNAMED (n_bits), unsigned attr)
{
/* Check attributes. */
if (attr & BITSET_FIXED && attr & BITSET_VARIABLE)
/* Set bit BITNO in bitset DST. */
static void
-abitset_set (MAYBE_UNUSED bitset dst, MAYBE_UNUSED bitset_bindex bitno)
+abitset_set (bitset UNNAMED (dst), bitset_bindex UNNAMED (bitno))
{
/* This should never occur for abitsets since we should always hit
the cache. It is likely someone is trying to access outside the
/* Reset bit BITNO in bitset DST. */
static void
-abitset_reset (MAYBE_UNUSED bitset dst,
- MAYBE_UNUSED bitset_bindex bitno)
+abitset_reset (bitset UNNAMED (dst), bitset_bindex UNNAMED (bitno))
{
/* This should never occur for abitsets since we should always hit
the cache. It is likely someone is trying to access outside the
/* Test bit BITNO in bitset SRC. */
static bool
-abitset_test (MAYBE_UNUSED bitset src,
- MAYBE_UNUSED bitset_bindex bitno)
+abitset_test (bitset UNNAMED (src), bitset_bindex UNNAMED (bitno))
{
/* This should never occur for abitsets since we should always
hit the cache. */
/* Return size of initial structure. */
size_t
-lbitset_bytes (MAYBE_UNUSED bitset_bindex n_bits)
+lbitset_bytes (bitset_bindex UNNAMED (n_bits))
{
return sizeof (struct lbitset_struct);
}
/* Initialize a bitset. */
bitset
-lbitset_init (bitset bset, MAYBE_UNUSED bitset_bindex n_bits)
+lbitset_init (bitset bset, bitset_bindex n_bits)
{
BITSET_NBITS_ (bset) = n_bits;
bset->b.vtable = &lbitset_vtable;
/* Print all bitset statistics to FILE. */
static void
-bitset_stats_print (FILE *file, MAYBE_UNUSED bool verbose)
+bitset_stats_print (FILE *file, bool UNNAMED (verbose))
{
if (!bitset_stats_info)
return;
/* Return size of initial structure. */
size_t
-tbitset_bytes (MAYBE_UNUSED bitset_bindex n_bits)
+tbitset_bytes (bitset_bindex UNNAMED (n_bits))
{
return sizeof (struct tbitset_struct);
}
/* Reset bit BITNO in bitset DST. */
static void
-vbitset_reset (MAYBE_UNUSED bitset dst, MAYBE_UNUSED bitset_bindex bitno)
+vbitset_reset (bitset UNNAMED (dst), bitset_bindex UNNAMED (bitno))
{
/* We must be accessing outside the cache so the bit is
zero anyway. */
/* Test bit BITNO in bitset SRC. */
static bool
-vbitset_test (MAYBE_UNUSED bitset src,
- MAYBE_UNUSED bitset_bindex bitno)
+vbitset_test (bitset UNNAMED (src), bitset_bindex UNNAMED (bitno))
{
/* We must be accessing outside the cache so the bit is
zero anyway. */
size_t
-vbitset_bytes (MAYBE_UNUSED bitset_bindex n_bits)
+vbitset_bytes (bitset_bindex UNNAMED (n_bits))
{
return sizeof (struct vbitset_struct);
}
return NULL;
}
static ssize_t
-smack_new_label_from_path (MAYBE_UNUSED const char *path,
- MAYBE_UNUSED const char *xattr,
- MAYBE_UNUSED int follow, MAYBE_UNUSED char **label)
+smack_new_label_from_path (const char *UNNAMED (path),
+ const char *UNNAMED (xattr),
+ int UNNAMED (follow), char **UNNAMED (label))
{
return -1;
}
static ssize_t
-smack_new_label_from_file (MAYBE_UNUSED int fd,
- MAYBE_UNUSED const char *xattr,
- MAYBE_UNUSED char **label)
+smack_new_label_from_file (int UNNAMED (fd), const char *UNNAMED (xattr),
+ char **UNNAMED (label))
{
return -1;
}
/* Compare the inode numbers of two directory entries */
static int
-direntry_cmp_inode (void const *a, void const *b, MAYBE_UNUSED void *arg)
+direntry_cmp_inode (void const *a, void const *b, void *UNNAMED (arg))
{
direntry_t const *dea = a;
direntry_t const *deb = b;