Path: csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Word For Today: =?utf-8?Q?=E2=80=9CUglification=E2=80=9D?=
Date: Thu, 14 Mar 2024 10:23:01 -0700
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <86v85opw22.fsf@linuxsc.com>
References: <20240311202758.193@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="c73a7ccbfb7c95d529f92c065d1adb1d"; logging-data="1848520"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eoFjP5Vud+pw6wi4bhOooTyESzXJeZBg="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:bUYoQLcnkX2HROUkHuoBfFj6uJQ= sha1:teNrWkPsjkal8+GMgKX+uRnxifM=
Xref: csiph.com comp.lang.c:383607
Kaz Kylheku <433-929-6894@kylheku.com> writes:
[some editing of white space done]
> On 2024-03-12, Lawrence D'Oliveiro wrote:
>
>> From /usr/include/<>/bits/select.h on my Debian system:
>>
>> #define __FD_ZERO(s) \
>> do { \
>> unsigned int __i; \
>> fd_set *__arr = (s); \
>
> This assignment has value; it checks that, loosely speaking,
> s is an "assignment compatible" pointer with a fd_set *,
> so that there is a diagnostic if the macro is applied to
> an object of the wrong type.
More to the point, if the macro is applied to a value of the wrong
type.
>> for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \
>> __FDS_BITS (__arr)[__i] = 0; \
>
> Here, I would have done memset(__arr, 0, sizeof *__arr).
That assumes that it is the entire fd_set that needs to be zeroed,
which may not be right. Note the call to the __FDS_BITS() macro.
Better:
#define __FD_ZERO(s) ( \
(void) memset( \
__FDS_BITS( (fd_set*){(s)} ), 0, sizeof __FDS_BITS( (fd_set*){0} ) \
) \
)
This definition: avoids introducing any new identifiers; checks
that the argument s yields an assignment compatible pointer; and
provides a macro that can be used as a void expression (unlike the
original macro definition, which can be used only as a statement).