bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using C2x attributes more effectively in Gnulib


From: Paul Eggert
Subject: Re: Using C2x attributes more effectively in Gnulib
Date: Mon, 9 Aug 2021 03:08:50 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

On 8/7/21 6:40 PM, Bruno Haible wrote:

Also, draft C2x lets one write the above function without naming the
parameters, as follows:

    SE_SELINUX_INLINE int
    fsetfilecon (int, char const *)
      { errno = ENOTSUP; return -1; }

This is nicer than [[maybe_unused]], because it says the arguments are
*definitely* unused instead of merely *maybe* unused, and that allows a
bit more checking of the code.

I disagree on this one. For a human reader who wants to understand the code,
the parameter name is more important than its type.

OK, perhaps this would do instead (assuming C2x):

    SE_SELINUX_INLINE int
    fsetfilecon (int /*fd*/, char const * /*context*/)
      { errno = ENOTSUP; return -1; }
they have designed
this language feature from the perspective what the compiler needs in
order to generate machine code

It's more than just machine code. It's telling the reader that the arguments are definitely unused. This gives the reader more information than [[maybe_unused]] does.

It's a C2x feature I find helpful from a readability point of view, since I find the names to be clutter in situations like these. Indeed, I'd rather see something like this:

  SE_SELINUX_INLINE fsetfilecon { errno = ENOTSUP; return -1; }

since setfilecon's signature (which I can easily navigate to, or ask about) tells me all I need to know about the API that doesn't matter here.

Admittedly readability tastes differ.

I have personally used mixed-case macro names in GNU clisp, and I can
assert (in hindsight) that it did *not* contribute to maintainability.

Fair enough; let's stick to uppercase.

Hmm. This _GL_UNUSED macro is used a lot in .c code, simply because it
it short (and the "maybe" in _GL_ATTRIBUTE_MAYBE_UNUSED is more of a
compiler technicality).

It's not merely a technicality. I often write code where an argument may be unused, in the sense that there's an ifdef where it's used on some platforms but not others. MAYBE_UNUSED is helpful in this situations.

I'm OK with moving all _GL_UNUSED from after
the parameter declaration to before the parameter declaration. Then
we can continue to have
   #define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED

Yes, this sounds like a win. It's a lot simpler than my proposal. Although it loses a bit of information when the arg is definitely unused, perhaps that's not worth worrying about.

* Remove the snippet/unused-parameter module as it's not used now.

Indeed, this module is unused in gnulib. It may be used in packages that
use gnulib; therefore I vote for marking it 'obsolete' and remove it only
in a year or two.

Sounds good to me too.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]