On Fri, Jul 05, 2024 at 10:03:05AM -0400, Mouse wrote:
> In...C++, I think it is?, you can do this by declaring the unused arg
> without a name, as in
> 
> void fxn(int arg1, int)
> {
>  ...
> }
> 
> but as far as I know nobody's picked that up in C.  (It strikes me as a
> very sensible approach.)
Then you need to update your knowledge: this is now standard C23.

> (I suspect
> use of compilers that handle (void)arg or __attribute__ is commoner
> than the presence of __USE or whatever).
Your suspicion is correct here: void casts are universal,
unused-tagging will functionally work everywhere
(or, at the very least, not not work),
whereas __USE is a NetBSD macro:
  sys/sys/cdefs.h:#define __USE(a) (/*LINTED*/(void)(a))
and NetBSD uses it liberally
(I also interrogated OpenBSD (no hits)
 and FreeBSD (four hits, all below a directory that said "netbsd-...")).

If you want to ignore an argument and don't want to nominally target C23,
use (void)arg; otherwise just don't name it.

If you have a variable that's used compile-time-conditionally,
tag it __attribute__((unused)) (<C23) or [[maybe_unused]] (≥C23).

Best,

Attachment: signature.asc
Description: PGP signature

Reply via email to