Re: Results of survey re. a new array size operator

Liste des GroupesRevenir à cl c 
Sujet : Re: Results of survey re. a new array size operator
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.c
Date : 29. Jan 2025, 10:48:46
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <868qqu2bnl.fsf@linuxsc.com>
References : 1 2 3 4 5 6
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Kaz Kylheku <643-408-1753@kylheku.com> writes:

On 2025-01-24, Scott Lurndal <scott@slp53.sl.home> wrote:
>
Kaz Kylheku <643-408-1753@kylheku.com> writes:
>
On 2025-01-24, Scott Lurndal <scott@slp53.sl.home> wrote:
You can define
>
 #define arraysize (x) (sizeof (x) / sizeof ((x)[0))
>
You can, but you don't need to.
>
The repetition in things like:
>
  sizeof foo->bar.buf / *sizeof foo->bar.buf
>
is just irksome.  Why do I have to say that thing twice,
to get its number of elements?
>
Often readability suffers
when you use macros, not to mention the other quirks of
C macro use (in C++, a constexpr function might be
suitable, but the naming being arbitrary (e.g. arraysize,
NUM_ELEMENTS, SIZE, et alia) doesn't aid in readability
or maintainability.
>
The naming being arbitrary is the argument for standardizing the
name for the macro and sticking it into, for instance, <stddef.h>.
>
If we didn't have offsetof there, we might have to deal with
OFFSETOF, offsetof, offset, member_offset, and others.

That's a flawed analogy.  A macro to compute the number of
elements in an array can be done in standard C.  The
functionality of offsetof cannot be done in standard C, and
that's what it needs to be in the standard library.

Date Sujet#  Auteur
24 Jan 25 * Results of survey re. a new array size operator36Alexis
24 Jan 25 +* Re: Results of survey re. a new array size operator10Michael S
24 Jan 25 i`* Re: Results of survey re. a new array size operator9Kaz Kylheku
25 Jan 25 i `* Re: Results of survey re. a new array size operator8Kaz Kylheku
29 Jan 25 i  `* Re: Results of survey re. a new array size operator7Tim Rentsch
29 Jan 25 i   `* Re: Results of survey re. a new array size operator6bart
29 Jan 25 i    +- Re: Results of survey re. a new array size operator1Michael S
29 Jan 25 i    +* Re: Results of survey re. a new array size operator2Richard Damon
29 Jan 25 i    i`- Re: Results of survey re. a new array size operator1Tim Rentsch
29 Jan 25 i    +- Re: Results of survey re. a new array size operator1James Kuyper
29 Jan 25 i    `- Re: Results of survey re. a new array size operator1Tim Rentsch
24 Jan 25 +* Re: Results of survey re. a new array size operator13James Kuyper
24 Jan 25 i+* Re: Results of survey re. a new array size operator5Kaz Kylheku
25 Jan 25 ii+* Re: Results of survey re. a new array size operator3James Kuyper
25 Jan 25 iii`* Re: Results of survey re. a new array size operator2Kaz Kylheku
25 Jan 25 iii `- Re: Results of survey re. a new array size operator1James Kuyper
29 Jan 25 ii`- Re: Results of survey re. a new array size operator1Tim Rentsch
25 Jan 25 i`* Re: Results of survey re. a new array size operator7Waldek Hebisch
25 Jan 25 i +- Re: Results of survey re. a new array size operator1Kaz Kylheku
25 Jan 25 i `* Re: Results of survey re. a new array size operator5James Kuyper
25 Jan 25 i  `* Re: Results of survey re. a new array size operator4Waldek Hebisch
26 Jan 25 i   `* Re: Results of survey re. a new array size operator3Keith Thompson
26 Jan 25 i    +- Re: Results of survey re. a new array size operator1Waldek Hebisch
29 Jan 25 i    `- Re: Results of survey re. a new array size operator1Tim Rentsch
24 Jan 25 +* Re: Results of survey re. a new array size operator4Kaz Kylheku
24 Jan 25 i+* Re: Results of survey re. a new array size operator2Alexis
25 Jan 25 ii`- Re: Results of survey re. a new array size operator1Kaz Kylheku
29 Jan 25 i`- Re: Results of survey re. a new array size operator1Tim Rentsch
29 Jan 25 +- Re: Results of survey re. a new array size operator1Tim Rentsch
29 Jan 25 `* Re: Results of survey re. a new array size operator7Ben Bacarisse
29 Jan 25  `* Re: Results of survey re. a new array size operator6David Brown
30 Jan 25   `* Re: Results of survey re. a new array size operator5Ben Bacarisse
30 Jan 25    +- Re: Results of survey re. a new array size operator1David Brown
30 Jan 25    `* Re: Results of survey re. a new array size operator3Tim Rentsch
30 Jan 25     +- Re: Results of survey re. a new array size operator1Kaz Kylheku
19 Feb 25     `- Re: Results of survey re. a new array size operator1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal