Sujet : Re: Word For Today: “Uglification”
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.cDate : 14. Mar 2024, 18:23:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86v85opw22.fsf@linuxsc.com>
References : 1 2
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Kaz Kylheku <
433-929-6894@kylheku.com> writes:
[some editing of white space done]
On 2024-03-12, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
>
From /usr/include/<<arch>>/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).