Re: [PATCH v2] CodingGuidelines: also mention MAYBE_UNUSED
- From
Jeff King <peff@peff.net>
- Date
- Aug 29, 2024, 19:40 UTC
- Message-ID
- <20240829194054.GC423429@coredump.intra.peff.net>
- In-Reply-To
- <xmqq4j73w5up.fsf_-_@gitster.g>
On Thu, Aug 29, 2024 at 11:18:06AM -0700, Junio C Hamano wrote:
Show 12 quoted lines
> +/* > + * MAYBE_UNUSED marks a function parameter that may be unused, but > + * whose use is not an error. It also can be used to annotate a > + * function, a variable, or a type that may be unused. > + * > + * Depending on a configuration, all uses of such a thing may become > + * #ifdef'ed away. Marking it with UNUSED would give a warning in a > + * compilation where it is indeed used, and not marking it at all > + * would give a warning in a compilation where it is unused. In such > + * a case, MAYBE_UNUSED is the appropriate annotation to use. > + */ > #define MAYBE_UNUSED __attribute__((__unused__))
Thanks, I think this is good. There's more nuanced discussion about when the "MAYBE" variant could be used for non-parameters, but I don't know that it's worth trying to enumerate every place we've found it useful.
-Peff