Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

If a 'train station' is where a train stops, what's a 'workstation'?


devel / comp.lang.c / Re: Effect of CPP tags

SubjectAuthor
* Effect of CPP tagsJanis Papanagnou
+- Re: Effect of CPP tagsLowell Gilbert
+* Re: Effect of CPP tagsKaz Kylheku
|`* Re: Effect of CPP tagsSpiros Bousbouras
| `- Re: Effect of CPP tagsTim Rentsch
+* Re: Effect of CPP tagsJanis Papanagnou
|+* Re: Effect of CPP tagsLowell Gilbert
||+* Re: Effect of CPP tagsKeith Thompson
|||`* Re: Effect of CPP tagsKaz Kylheku
||| `* Re: Effect of CPP tagsKeith Thompson
|||  `* Re: Effect of CPP tagsTim Rentsch
|||   `* Re: Effect of CPP tagsKaz Kylheku
|||    +- Re: Effect of CPP tagsJames Kuyper
|||    +* Re: Effect of CPP tagsJames Kuyper
|||    |`* Re: Effect of CPP tagsKaz Kylheku
|||    | +* Re: Effect of CPP tagsJames Kuyper
|||    | |`- Re: Effect of CPP tagsTim Rentsch
|||    | `* Re: Effect of CPP tagsTim Rentsch
|||    |  `* Re: Effect of CPP tagsKeith Thompson
|||    |   +- Re: Effect of CPP tagsDavid Brown
|||    |   +* Re: Effect of CPP tagsTim Rentsch
|||    |   |`- Re: Effect of CPP tagsKeith Thompson
|||    |   `- Re: Effect of CPP tagsTim Rentsch
|||    `- Re: Effect of CPP tagsTim Rentsch
||+* Re: Effect of CPP tagsKaz Kylheku
|||+- Re: Effect of CPP tagsKaz Kylheku
|||`* Re: Effect of CPP tagsLowell Gilbert
||| `- Re: Effect of CPP tagsJanis Papanagnou
||`* Re: Effect of CPP tagsJanis Papanagnou
|| `- Re: Effect of CPP tagsKaz Kylheku
|+- Re: Effect of CPP tagsKaz Kylheku
|`* Re: Effect of CPP tagsScott Lurndal
| +* Re: Effect of CPP tagsJanis Papanagnou
| |`* Re: Effect of CPP tagsKeith Thompson
| | +* Re: Effect of CPP tagsScott Lurndal
| | |`* Re: Effect of CPP tagsDavid Brown
| | | `* Re: Effect of CPP tagsJames Kuyper
| | |  `- Re: Effect of CPP tagsDavid Brown
| | `- Re: Effect of CPP tagsTim Rentsch
| `- usleep (Was: Effect of CPP tags)Kenny McCormack
+* Re: Effect of CPP tagsLawrence D'Oliveiro
|`* Re: Effect of CPP tagsBart
| +* Re: Effect of CPP tagsDavid Brown
| |`* Re: Effect of CPP tagsKeith Thompson
| | `* Re: Effect of CPP tagsKaz Kylheku
| |  `* Re: Effect of CPP tagsBart
| |   +* Re: Effect of CPP tagsLawrence D'Oliveiro
| |   |`* Re: Effect of CPP tagsBart
| |   | `* Re: Effect of CPP tagsLawrence D'Oliveiro
| |   |  `* Re: Effect of CPP tagsBart
| |   |   +* Re: Effect of CPP tagsScott Lurndal
| |   |   |+* Re: Effect of CPP tagsDavid Brown
| |   |   ||`- Re: Effect of CPP tagsBGB
| |   |   |`* Re: Effect of CPP tagsBart
| |   |   | `- Re: Effect of CPP tagsDavid Brown
| |   |   `- Re: Effect of CPP tagsLawrence D'Oliveiro
| |   `* Re: Effect of CPP tagsDavid Brown
| |    +* Re: Effect of CPP tagsBart
| |    |+- Re: Effect of CPP tagsScott Lurndal
| |    |+* Re: Effect of CPP tagsKaz Kylheku
| |    ||+* Re: Effect of CPP tagsBart
| |    |||`* Re: Effect of CPP tagsBart
| |    ||| +- Re: Effect of CPP tagsKeith Thompson
| |    ||| `* Re: Effect of CPP tagsKaz Kylheku
| |    |||  `* Re: Effect of CPP tagsKeith Thompson
| |    |||   +* Re: Effect of CPP tagsJanis Papanagnou
| |    |||   |`- Re: Effect of CPP tagsKeith Thompson
| |    |||   `- Re: Effect of CPP tagsKaz Kylheku
| |    ||`- Re: Effect of CPP tagsScott Lurndal
| |    |`- Re: Effect of CPP tagsDavid Brown
| |    `* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     +* Re: Effect of CPP tagsChris M. Thomasson
| |     |`* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     | `* Re: Effect of CPP tagsChris M. Thomasson
| |     |  `* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     |   +- Re: Effect of CPP tagsChris M. Thomasson
| |     |   +- Re: Effect of CPP tagsChris M. Thomasson
| |     |   +- Re: Effect of CPP tagsKaz Kylheku
| |     |   `- Re: Effect of CPP tagsBlue-Maned_Hawk
| |     +* Re: Effect of CPP tagsDavid Brown
| |     |+* Re: Effect of CPP tagsBart
| |     ||+* Re: Effect of CPP tagsDavid Brown
| |     |||+- Re: Effect of CPP tagsBlue-Maned_Hawk
| |     |||`* Re: Effect of CPP tagsBart
| |     ||| `* Re: Effect of CPP tagsDavid Brown
| |     |||  `* Re: Effect of CPP tagsBart
| |     |||   +* Re: Effect of CPP tagsChris M. Thomasson
| |     |||   |`- Re: Effect of CPP tagsChris M. Thomasson
| |     |||   +* Re: Effect of CPP tagstTh
| |     |||   |+- Re: Effect of CPP tagsLawrence D'Oliveiro
| |     |||   |+- Re: Effect of CPP tagsKaz Kylheku
| |     |||   |`* Re: Effect of CPP tagsBart
| |     |||   | `* Re: Effect of CPP tagsScott Lurndal
| |     |||   |  `* Re: Effect of CPP tagsBart
| |     |||   |   `* Re: Effect of CPP tagsDavid Brown
| |     |||   |    +* Re: Effect of CPP tagsKaz Kylheku
| |     |||   |    |`* Re: Effect of CPP tagsDavid Brown
| |     |||   |    | `- Re: Effect of CPP tagsKaz Kylheku
| |     |||   |    `* Re: Effect of CPP tagsBart
| |     |||   |     +* Re: Effect of CPP tagsScott Lurndal
| |     |||   |     |`* Re: Effect of CPP tagsBart
| |     |||   |     `* Re: Effect of CPP tagsDavid Brown
| |     |||   `* Re: Effect of CPP tagsDavid Brown
| |     ||`* Re: Effect of CPP tagsBlue-Maned_Hawk
| |     |`* Re: Effect of CPP tagsLawrence D'Oliveiro
| |     `* Re: Effect of CPP tagsKaz Kylheku
| +- Re: Effect of CPP tagsRichard Damon
| +* Re: Effect of CPP tagsKaz Kylheku
| +* Re: Effect of CPP tagsBlue-Maned_Hawk
| `- Re: Effect of CPP tagsLawrence D'Oliveiro
`* Re: Effect of CPP tagsTim Rentsch

Pages:123456789101112131415161718192021222324252627
Re: Effect of CPP tags

<un6q52$3nsfu$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30593&group=comp.lang.c#30593

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 12:33:22 -0500
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <un6q52$3nsfu$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me> <ummmqe$s4od$1@dont-email.me>
<87o7e8voy1.fsf@nosuchdomain.example.com> <20231229122012.850@kylheku.com>
<umnhtf$103sg$1@dont-email.me> <ums14k$1p0rs$1@dont-email.me>
<umsnbn$1ro5b$7@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un42nr$38vqs$1@dont-email.me>
<87il4at7pf.fsf@nosuchdomain.example.com> <un65po$3l03p$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 4 Jan 2024 17:33:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ac97f9a6e8e328f641d7c08ef6026495";
logging-data="3928574"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Lb7tFV/WF31id2eQXyOk482z92t3QmZM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:gTh1/I0DaJau271pKgmE5CgRz3c=
Content-Language: en-US
In-Reply-To: <un65po$3l03p$1@dont-email.me>
 by: James Kuyper - Thu, 4 Jan 2024 17:33 UTC

On 1/4/24 06:46, David Brown wrote:
> On 03/01/2024 22:42, Keith Thompson wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>>> On 02/01/2024 21:24, Bart wrote:
>> [...]
>>>> The X-macro solution was this, adapted from the first answer here
>>>> (https://stackoverflow.com/questions/6635851/real-world-use-of-x-macros);
>>>> assume those functions are in scope:
>>>> -------
>>>> #define STATE_TABLE \
>>>>         ENTRY(STATE0, func0) \
>>>>         ENTRY(STATE1, func1) \
>>>>         ENTRY(STATE2, func2) \
>>>>         ENTRY(STATE3, func3) \
>>>> enum
>>>> {
>>>> #define ENTRY(a,b) a,
>>>>     STATE_TABLE
>>>> #undef ENTRY
>>>>     NUM_STATES
>>>> };
>>>> void* jumptable[NUM_STATES] =
>>>> {
>>>> #define ENTRY(a,b) b,
>>>>     STATE_TABLE
>>>> #undef ENTRY
>>>> };
>>>> -------
>>>
>>> (Why did you change the type from "p_func_t" to "void*" ? Was it just
>>> to annoy myself and other C programmers with a pointless and
>>> constraint-violating cast of a function pointer to "void*" ? Just add
>>> a suitable typedef - "typedef void(*p_func_t)(void);" )
>>
>> What constraint does it violate? And what cast are you referring to?
>
> I believe the initialisation follows the requirements for simple
> assignment, and function pointers are not compatible with void*.

You're right, for initialization "the same type constraints and
conversions as for simple assignment apply,". This initialization
violates those constraints. There's two options listed in 6.5.16.1p1
that might apply: since the object is a pointer, the initializer could
be a pointer to a compatible type. Since the object is, in particular, a
void*, it could be a pointer to an object type - but this initializer
doesn't qualify for either of those cases.
However, it was the cast you described as "constraint-violating", not
the initialization, and that's what's incorrect.

Re: Effect of CPP tags

<un6r6m$3nsfu$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30594&group=comp.lang.c#30594

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 12:51:18 -0500
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <un6r6m$3nsfu$2@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me> <ummmqe$s4od$1@dont-email.me>
<87o7e8voy1.fsf@nosuchdomain.example.com> <20231229122012.850@kylheku.com>
<umnhtf$103sg$1@dont-email.me> <ums14k$1p0rs$1@dont-email.me>
<umsnbn$1ro5b$7@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un42nr$38vqs$1@dont-email.me>
<87il4at7pf.fsf@nosuchdomain.example.com> <un65po$3l03p$1@dont-email.me>
<un68qj$3lbuq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 4 Jan 2024 17:51:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ac97f9a6e8e328f641d7c08ef6026495";
logging-data="3928574"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tUw/4NbiNqNvysyd6wkA4mgYz9rfNjZk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:nxBMiY2TRhBSiGw2fgAzS6GY15U=
Content-Language: en-US
In-Reply-To: <un68qj$3lbuq$1@dont-email.me>
 by: James Kuyper - Thu, 4 Jan 2024 17:51 UTC

On 1/4/24 07:37, Bart wrote:
> On 04/01/2024 11:46, David Brown wrote:
>> On 03/01/2024 22:42, Keith Thompson wrote:
>>> David Brown <david.brown@hesbynett.no> writes:
>>>> On 02/01/2024 21:24, Bart wrote:
>>> [...]
>>>>> The X-macro solution was this, adapted from the first answer here
>>>>> (https://stackoverflow.com/questions/6635851/real-world-use-of-x-macros); assume those functions are in scope:
>>>>> -------
>>>>> #define STATE_TABLE \
>>>>>           ENTRY(STATE0, func0) \
>>>>>           ENTRY(STATE1, func1) \
>>>>>           ENTRY(STATE2, func2) \
>>>>>           ENTRY(STATE3, func3) \
>>>>> enum
>>>>> {
>>>>> #define ENTRY(a,b) a,
>>>>>       STATE_TABLE
>>>>> #undef ENTRY
>>>>>       NUM_STATES
>>>>> };
>>>>> void* jumptable[NUM_STATES] =
>>>>> {
>>>>> #define ENTRY(a,b) b,
>>>>>       STATE_TABLE
>>>>> #undef ENTRY
>>>>> };
>>>>> -------
>>>>
>>>> (Why did you change the type from "p_func_t" to "void*" ?  Was it just
>>>> to annoy myself and other C programmers with a pointless and
>>>> constraint-violating cast of a function pointer to "void*" ?  Just add
>>>> a suitable typedef - "typedef void(*p_func_t)(void);" )
>>>
>>> What constraint does it violate?  And what cast are you referring to?
>>
>> I believe the initialisation follows the requirements for simple
>> assignment, and function pointers are not compatible with void*.  Bart
>> (for reasons understood only by him) uses void* pointers when he wants
>> generic function pointers.  The stack overflow link uses "p_func_t",
>> which is a function pointer typedef.
>>
>>
>
> The SO link didn't define p_func_t that I could see. ...

It also didn't provide declarations for func0, func1, func2, func3, or
FuncX. From C's rules for initialization, you should have concluded that
it was a pointer to a function type that is compatible with the types of
those functions.

> ... I changed it to
> void* to avoid the bother of doing so when testing, and to avoid having
> to include that in my example that would be a distraction.

You don't consider it distracting that void* makes it a constraint
violation, rendering the behavior of any program that uses such code
undeifined?

Re: Effect of CPP tags

<un6svh$3o7pk$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30595&group=comp.lang.c#30595

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.cm (Bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 18:21:38 +0000
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <un6svh$3o7pk$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me> <ummmqe$s4od$1@dont-email.me>
<87o7e8voy1.fsf@nosuchdomain.example.com> <20231229122012.850@kylheku.com>
<umnhtf$103sg$1@dont-email.me> <ums14k$1p0rs$1@dont-email.me>
<umsnbn$1ro5b$7@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un42nr$38vqs$1@dont-email.me>
<87il4at7pf.fsf@nosuchdomain.example.com> <un65po$3l03p$1@dont-email.me>
<un68qj$3lbuq$1@dont-email.me> <un6r6m$3nsfu$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 4 Jan 2024 18:21:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b2b9baa6625c35c2e3f0e524f125ac00";
logging-data="3940148"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+pqdFWBimelKxx64KU+JrlspaXx5P8SJ0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Le1txt42KU7ri9GESEXANgBprek=
In-Reply-To: <un6r6m$3nsfu$2@dont-email.me>
Content-Language: en-GB
 by: Bart - Thu, 4 Jan 2024 18:21 UTC

On 04/01/2024 17:51, James Kuyper wrote:
> On 1/4/24 07:37, Bart wrote:

>> The SO link didn't define p_func_t that I could see. ...
>
> It also didn't provide declarations for func0, func1, func2, func3, or
> FuncX. From C's rules for initialization, you should have concluded that
> it was a pointer to a function type that is compatible with the types of
> those functions.
>
>> ... I changed it to
>> void* to avoid the bother of doing so when testing, and to avoid having
>> to include that in my example that would be a distraction.
>
> You don't consider it distracting that void* makes it a constraint
> violation, rendering the behavior of any program that uses such code
> undeifined?

Only to people obsessed with Standards minutiae.

I can't remember if I only did a preprocessing test, or added enough
(declarations for functions etc) to compile, but here is a version
within a working program that I've just done:

-------------
#include <stdio.h>

void func0(void){}
void func1(void){}
void func2(void){}
void func3(void){}

#define STATE_TABLE \
ENTRY(STATE0, func0) \
ENTRY(STATE1, func1) \
ENTRY(STATE2, func2) \
ENTRY(STATE3, func3) \

enum
{ #define ENTRY(a,b) a,
STATE_TABLE
#undef ENTRY
NUM_STATES
};

void* jumptable[NUM_STATES] =
{ #define ENTRY(a,b) b,
STATE_TABLE
#undef ENTRY
};

int main(void) {
printf("%d\n", NUM_STATES);
printf("%d %p\n", STATE0, jumptable[STATE0]);
printf("%d %p\n", STATE1, jumptable[STATE1]);
printf("%d %p\n", STATE2, jumptable[STATE2]);
printf("%d %p\n", STATE3, jumptable[STATE3]);
} -------------

I tested it on 5 compilers and it gave the expected results. It shows
that the x-macro works, it's just unwieldy.

Re: Effect of CPP tags

<un6toq$3ogqm$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30596&group=comp.lang.c#30596

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.cm (Bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 18:35:06 +0000
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <un6toq$3ogqm$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 4 Jan 2024 18:35:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b2b9baa6625c35c2e3f0e524f125ac00";
logging-data="3949398"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tZsSJn56yfJ73BY16b9yR0WkjByZUynk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:iQDd0x+YRfKo7O5PVF7ondkAMtU=
In-Reply-To: <RJAlN.141573$c3Ea.132913@fx10.iad>
Content-Language: en-GB
 by: Bart - Thu, 4 Jan 2024 18:35 UTC

On 04/01/2024 16:08, Scott Lurndal wrote:
> Bart <bc@freeuk.cm> writes:
>> On 04/01/2024 01:57, Scott Lurndal wrote:

>>> Good thing I don't use single letter identifiers.
>>>
>>
>> What are you, 5 years old?
>>
>> A and B are placeholders for arbitrary identifiers of any length.
>>
>> How about if I change my remark to:
>>
>> "Because
>> sizeof(pentium_msr_passthrough_with_knobs_on)/sizeof(k6_msr_passthrough_with_knobs_on)
>> would be legal code when both pentium_msr_passthrough_with_knobs_on and
>> k6_msr_passthrough_with_knobs_on are arrays."
>
> It's pretty obvious to even the meanest programmer that code is incorrect.

Is it? How do you know? The code is valid:

--------
int pentium_msr_passthrough_with_knobs_on;
int k6_msr_passthrough_with_knobs_on;

int main(void) {
sizeof(pentium_msr_passthrough_with_knobs_on)/sizeof(k6_msr_passthrough_with_knobs_on);
} --------

This compiles fine. It is valid C. But what does it mean? Given more
suitable types for those expressions, is it an incorrect attempt to get
an array length, or something else entirely?

Using this definition of the first variable:

int pentium_msr_passthrough_with_knobs_on[13];

Then it does in fact evaluate its length, although partly by coincidence
as both base-types are 'int'.

(Now you're going to point out that it doesn't use that value; yes, we
know.)

Here's the same experiment with my language:

int pentium_msr_passthrough_with_knobs_on
int k6_msr_passthrough_with_knobs_on

proc main=
pentium_msr_passthrough_with_knobs_on.len
end

This is more transparent: it's definitely evaluating the length of that
variable, but it fails because it is not an array. If I add that '[13]'
(here it goes at the left), then it works.

Now look at the basketcase that is C's attempt. C could EASILY have had
an equivalent op that works like 'size'of'; it chose not to.

Why is everyone trying to make out that C's approach is superior when it
clearly isn't?

Re: Effect of CPP tags

<87edext07g.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30597&group=comp.lang.c#30597

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 04 Jan 2024 10:36:35 -0800
Organization: None to speak of
Lines: 55
Message-ID: <87edext07g.fsf@nosuchdomain.example.com>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me> <ummmqe$s4od$1@dont-email.me>
<87o7e8voy1.fsf@nosuchdomain.example.com>
<20231229122012.850@kylheku.com> <umnhtf$103sg$1@dont-email.me>
<ums14k$1p0rs$1@dont-email.me> <umsnbn$1ro5b$7@dont-email.me>
<umuj4q$28384$1@dont-email.me> <umun7n$28l7q$1@dont-email.me>
<un0pb2$2kp7q$1@dont-email.me> <un1clg$2oq9u$1@dont-email.me>
<un1hek$2ph62$1@dont-email.me> <un1rdk$2quec$1@dont-email.me>
<un42nr$38vqs$1@dont-email.me>
<87il4at7pf.fsf@nosuchdomain.example.com>
<un65po$3l03p$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="ffdb02b37e21d19b8cbab9b0b36b1681";
logging-data="3946183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195Fvnva8MlmQgjhS01l+72"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:hMlUOwsTxqQuNyTOGCiyzYeEuyo=
sha1:rhsYK2HLA/OFbioB9NntAWqPRWE=
 by: Keith Thompson - Thu, 4 Jan 2024 18:36 UTC

David Brown <david.brown@hesbynett.no> writes:
> On 03/01/2024 22:42, Keith Thompson wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>>> On 02/01/2024 21:24, Bart wrote:
>> [...]
>>>> The X-macro solution was this, adapted from the first answer here
>>>> (https://stackoverflow.com/questions/6635851/real-world-use-of-x-macros); assume those functions are in scope:
>>>> -------
>>>> #define STATE_TABLE \
>>>>         ENTRY(STATE0, func0) \
>>>>         ENTRY(STATE1, func1) \
>>>>         ENTRY(STATE2, func2) \
>>>>         ENTRY(STATE3, func3) \
>>>> enum
>>>> {
>>>> #define ENTRY(a,b) a,
>>>>     STATE_TABLE
>>>> #undef ENTRY
>>>>     NUM_STATES
>>>> };
>>>> void* jumptable[NUM_STATES] =
>>>> {
>>>> #define ENTRY(a,b) b,
>>>>     STATE_TABLE
>>>> #undef ENTRY
>>>> };
>>>> -------
>>>
>>> (Why did you change the type from "p_func_t" to "void*" ? Was it just
>>> to annoy myself and other C programmers with a pointless and
>>> constraint-violating cast of a function pointer to "void*" ? Just add
>>> a suitable typedef - "typedef void(*p_func_t)(void);" )
>> What constraint does it violate? And what cast are you referring
>> to?
>
> I believe the initialisation follows the requirements for simple
> assignment, and function pointers are not compatible with void*. Bart
> (for reasons understood only by him) uses void* pointers when he wants
> generic function pointers. The stack overflow link uses "p_func_t",
> which is a function pointer typedef.

Bart's code initializes array elements of type void* with values that
are presumably of pointer-to-function type. That is indeed a constraint
violation (one that, unfortunately, gcc doesn't even warn about with
default options).

David, your use of the word "cast" confused me. What's happening in the
code is an implicit conversion, not a cast (or it would be if that
particular implicit conversion were defined in the language, or if
you're using a non-standard C dialect that defines it).

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Effect of CPP tags

<87a5plszv5.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30598&group=comp.lang.c#30598

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 04 Jan 2024 10:43:58 -0800
Organization: None to speak of
Lines: 84
Message-ID: <87a5plszv5.fsf@nosuchdomain.example.com>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me> <ummmqe$s4od$1@dont-email.me>
<87o7e8voy1.fsf@nosuchdomain.example.com>
<20231229122012.850@kylheku.com> <umnhtf$103sg$1@dont-email.me>
<ums14k$1p0rs$1@dont-email.me> <umsnbn$1ro5b$7@dont-email.me>
<umuj4q$28384$1@dont-email.me> <umun7n$28l7q$1@dont-email.me>
<un0pb2$2kp7q$1@dont-email.me> <un1clg$2oq9u$1@dont-email.me>
<un1hek$2ph62$1@dont-email.me> <un1rdk$2quec$1@dont-email.me>
<un42nr$38vqs$1@dont-email.me>
<87il4at7pf.fsf@nosuchdomain.example.com>
<un65po$3l03p$1@dont-email.me> <un68qj$3lbuq$1@dont-email.me>
<un6r6m$3nsfu$2@dont-email.me> <un6svh$3o7pk$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="ffdb02b37e21d19b8cbab9b0b36b1681";
logging-data="3946183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CH80fpZbL1U7HG8Y3lLTn"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:qQ6eKjszVSj6Jrp2HQpETNogeIg=
sha1:C5hNmxw8+VZOwRLFSPvuz1C5KnM=
 by: Keith Thompson - Thu, 4 Jan 2024 18:43 UTC

Bart <bc@freeuk.cm> writes:
> On 04/01/2024 17:51, James Kuyper wrote:
>> On 1/4/24 07:37, Bart wrote:
>
>>> The SO link didn't define p_func_t that I could see. ...
>> It also didn't provide declarations for func0, func1, func2, func3,
>> or
>> FuncX. From C's rules for initialization, you should have concluded that
>> it was a pointer to a function type that is compatible with the types of
>> those functions.
>>
>>> ... I changed it to
>>> void* to avoid the bother of doing so when testing, and to avoid having
>>> to include that in my example that would be a distraction.
>> You don't consider it distracting that void* makes it a constraint
>> violation, rendering the behavior of any program that uses such code
>> undeifined?
>
> Only to people obsessed with Standards minutiae.

I.e., concerned about correctness of C code.

> I can't remember if I only did a preprocessing test, or added enough
> (declarations for functions etc) to compile, but here is a version
> within a working program that I've just done:
>
> -------------
> #include <stdio.h>
>
> void func0(void){}
> void func1(void){}
> void func2(void){}
> void func3(void){}
>
> #define STATE_TABLE \
> ENTRY(STATE0, func0) \
> ENTRY(STATE1, func1) \
> ENTRY(STATE2, func2) \
> ENTRY(STATE3, func3) \
>
> enum
> {
> #define ENTRY(a,b) a,
> STATE_TABLE
> #undef ENTRY
> NUM_STATES
> };
>
> void* jumptable[NUM_STATES] =
> {
> #define ENTRY(a,b) b,
> STATE_TABLE
> #undef ENTRY
> };
>
> int main(void) {
> printf("%d\n", NUM_STATES);
> printf("%d %p\n", STATE0, jumptable[STATE0]);
> printf("%d %p\n", STATE1, jumptable[STATE1]);
> printf("%d %p\n", STATE2, jumptable[STATE2]);
> printf("%d %p\n", STATE3, jumptable[STATE3]);
> }
> -------------
>
> I tested it on 5 compilers and it gave the expected results. It shows
> that the x-macro works, it's just unwieldy.

You didn't test it with a *conforming* C compiler. Most C compilers
are not conforming by default (which I personally consider to
be unfortunate).

On my system, both gcc and clang compile that code with no errors
or warnings, and it appears to execute correctly. But both "gcc
-pedantic" and "clang -pedantic" issue multiple warnings, and both
"gcc -pedantic-errors" and "clang -pedantic-errors" reject it.

I understand that you don't care about this, so there's no need
to repeat yourself. I'm not even saying you should care about it.
Most of us here do care about it, and I suggest you accept that.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Effect of CPP tags

<20240104105102.429@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30599&group=comp.lang.c#30599

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 18:57:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <20240104105102.429@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me> <ummmqe$s4od$1@dont-email.me>
<87o7e8voy1.fsf@nosuchdomain.example.com> <20231229122012.850@kylheku.com>
<umnhtf$103sg$1@dont-email.me> <ums14k$1p0rs$1@dont-email.me>
<umsnbn$1ro5b$7@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<20240103114626.282@kylheku.com> <un5r9o$3jivl$1@dont-email.me>
Injection-Date: Thu, 4 Jan 2024 18:57:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e86d7ed55a4386262bd5785b65adb8f4";
logging-data="3952492"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LCoWhK+lTsQTwgZgHp6JhgSOSFOeYDLU="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:PEiau1s+Q/k+wCOnZY+uC1rIy0E=
 by: Kaz Kylheku - Thu, 4 Jan 2024 18:57 UTC

On 2024-01-04, David Brown <david.brown@hesbynett.no> wrote:
> However, I think it is all too late for that. It certainly can't be
> added to <stddef.h> or <stdlib.h> - what would you call it without
> conflicting with existing names in existing code?

I would call it elems or something, and hide the identifier unless
a new dialect of C is being used.

E.g. in the case of gcc, it would not be revealed in <stddef.h> if
only -std=c23 is in effect; a newer dialect selection would be required.

The standard headers have been getting new identifiers, right?
Like many new functions in <math.h>.

Those are functions which have linkage, which presents an implementation
challenge on top of the declarations in the header being easy to hide.

A size operator for arrays doesn't have linkage to worry about.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Effect of CPP tags

<un72f1$3p72u$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30600&group=comp.lang.c#30600

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 20:55:13 +0100
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <un72f1$3p72u$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 4 Jan 2024 19:55:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3fba019a2aa023992563a4ad2e73cd0e";
logging-data="3972190"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182gurrHCVyhvNlUlhyFwGQ"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:OVy12K2DVbDFh5BAO64FGNpswNU=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <un6toq$3ogqm$1@dont-email.me>
 by: Janis Papanagnou - Thu, 4 Jan 2024 19:55 UTC

On 04.01.2024 19:35, Bart wrote:
>
> Now look at the basketcase that is C's attempt. C could EASILY have had
> an equivalent op that works like 'size'of'; it chose not to.

You're asking for an, say, 'nof_elements(A)', where there's currently
only a 'sizeof(A)/sizeof(A[0])' existing? - Is that the whole resume
of this overly bulky subthread?

Janis

Re: Effect of CPP tags

<un73om$3pd33$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30601&group=comp.lang.c#30601

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.cm (Bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 20:17:26 +0000
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <un73om$3pd33$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <un72f1$3p72u$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 4 Jan 2024 20:17:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b2b9baa6625c35c2e3f0e524f125ac00";
logging-data="3978339"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hD64g/OD1BdURuAoIuiW368Gfy9z4tVw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:mjBQZKwtKR8GFndlZCKCkoKLqGY=
In-Reply-To: <un72f1$3p72u$1@dont-email.me>
Content-Language: en-GB
 by: Bart - Thu, 4 Jan 2024 20:17 UTC

On 04/01/2024 19:55, Janis Papanagnou wrote:
> On 04.01.2024 19:35, Bart wrote:
>>
>> Now look at the basketcase that is C's attempt. C could EASILY have had
>> an equivalent op that works like 'size'of'; it chose not to.
>
> You're asking for an, say, 'nof_elements(A)', where there's currently
> only a 'sizeof(A)/sizeof(A[0])' existing? - Is that the whole resume
> of this overly bulky subthread?

Yes exactly.

If you're arguing that it is such a trivial matter that it is hardly
worth discussing, I can equally say that if it is that trivial, why
isn't it just built-in? How hard can it be?

The subthread was actually about the macro system, and this example was
one I gave where macros make it possible for every man and his dog to
create their own sloppy, incompatible workaround.

Every other app seems to provide their own version; I gave three where
so far we have ArraySize, SDL_arraysize, and ARRAY_SIZE.

You yourself have suggested 'nof_elements'. You see the problem?

I'm not actually too bothered about that (I know C is never going to
have anything that is that sensible), I'm arguing against attitudes like
yours that it doesn't matter.

My original point may have been this: suppose C's macro system didn't
exist. Would that have given enough impetus to whoever was or were
responsible for the language, to actually do it properly?

Since my conjecture was that C's macro scheme stopped it evolving normally.

Re: Effect of CPP tags

<un7674$3pmej$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30602&group=comp.lang.c#30602

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 21:59:16 +0100
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <un7674$3pmej$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me> <ummmqe$s4od$1@dont-email.me>
<87o7e8voy1.fsf@nosuchdomain.example.com> <20231229122012.850@kylheku.com>
<umnhtf$103sg$1@dont-email.me> <ums14k$1p0rs$1@dont-email.me>
<umsnbn$1ro5b$7@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un42nr$38vqs$1@dont-email.me>
<87il4at7pf.fsf@nosuchdomain.example.com> <un65po$3l03p$1@dont-email.me>
<87edext07g.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 4 Jan 2024 20:59:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2eccfe5df22ecb5cf938b51f38035704";
logging-data="3987923"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2RWKm2t4aH6/H2kf7/PJQZzU9DobYB2E="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:1G1u04oMxV6L5X14lj9y+eQIk48=
In-Reply-To: <87edext07g.fsf@nosuchdomain.example.com>
Content-Language: en-GB
 by: David Brown - Thu, 4 Jan 2024 20:59 UTC

On 04/01/2024 19:36, Keith Thompson wrote:
> David Brown <david.brown@hesbynett.no> writes:
>> On 03/01/2024 22:42, Keith Thompson wrote:
>>> David Brown <david.brown@hesbynett.no> writes:
>>>> On 02/01/2024 21:24, Bart wrote:
>>> [...]
>>>>> The X-macro solution was this, adapted from the first answer here
>>>>> (https://stackoverflow.com/questions/6635851/real-world-use-of-x-macros); assume those functions are in scope:
>>>>> -------
>>>>> #define STATE_TABLE \
>>>>>         ENTRY(STATE0, func0) \
>>>>>         ENTRY(STATE1, func1) \
>>>>>         ENTRY(STATE2, func2) \
>>>>>         ENTRY(STATE3, func3) \
>>>>> enum
>>>>> {
>>>>> #define ENTRY(a,b) a,
>>>>>     STATE_TABLE
>>>>> #undef ENTRY
>>>>>     NUM_STATES
>>>>> };
>>>>> void* jumptable[NUM_STATES] =
>>>>> {
>>>>> #define ENTRY(a,b) b,
>>>>>     STATE_TABLE
>>>>> #undef ENTRY
>>>>> };
>>>>> -------
>>>>
>>>> (Why did you change the type from "p_func_t" to "void*" ? Was it just
>>>> to annoy myself and other C programmers with a pointless and
>>>> constraint-violating cast of a function pointer to "void*" ? Just add
>>>> a suitable typedef - "typedef void(*p_func_t)(void);" )
>>> What constraint does it violate? And what cast are you referring
>>> to?
>>
>> I believe the initialisation follows the requirements for simple
>> assignment, and function pointers are not compatible with void*. Bart
>> (for reasons understood only by him) uses void* pointers when he wants
>> generic function pointers. The stack overflow link uses "p_func_t",
>> which is a function pointer typedef.
>
> Bart's code initializes array elements of type void* with values that
> are presumably of pointer-to-function type. That is indeed a constraint
> violation (one that, unfortunately, gcc doesn't even warn about with
> default options).
>
> David, your use of the word "cast" confused me. What's happening in the
> code is an implicit conversion, not a cast (or it would be if that
> particular implicit conversion were defined in the language, or if
> you're using a non-standard C dialect that defines it).
>

You are correct there - there was no cast in the code, so my wording was
wrong.

Re: Effect of CPP tags

<%cFlN.140487$xHn7.115393@fx14.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30603&group=comp.lang.c#30603

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx14.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Effect of CPP tags
Newsgroups: comp.lang.c
References: <umet9d$3hir9$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me> <un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me> <un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu> <un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad> <un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me> <un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad> <un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad> <un6toq$3ogqm$1@dont-email.me>
Lines: 42
Message-ID: <%cFlN.140487$xHn7.115393@fx14.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 04 Jan 2024 21:14:35 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 04 Jan 2024 21:14:35 GMT
X-Received-Bytes: 2225
 by: Scott Lurndal - Thu, 4 Jan 2024 21:14 UTC

Bart <bc@freeuk.cm> writes:
>On 04/01/2024 16:08, Scott Lurndal wrote:
>> Bart <bc@freeuk.cm> writes:
>>> On 04/01/2024 01:57, Scott Lurndal wrote:
>
>>>> Good thing I don't use single letter identifiers.
>>>>
>>>
>>> What are you, 5 years old?
>>>
>>> A and B are placeholders for arbitrary identifiers of any length.
>>>
>>> How about if I change my remark to:
>>>
>>> "Because
>>> sizeof(pentium_msr_passthrough_with_knobs_on)/sizeof(k6_msr_passthrough_with_knobs_on)
>>> would be legal code when both pentium_msr_passthrough_with_knobs_on and
>>> k6_msr_passthrough_with_knobs_on are arrays."
>>
>> It's pretty obvious to even the meanest programmer that code is incorrect.
>
>Is it? How do you know? The code is valid:
>
>--------
>int pentium_msr_passthrough_with_knobs_on;
>int k6_msr_passthrough_with_knobs_on;
>
>int main(void) {
>sizeof(pentium_msr_passthrough_with_knobs_on)/sizeof(k6_msr_passthrough_with_knobs_on);
>}
>--------
>
>This compiles fine.

So what? Any programmer will see that they don't
match immediately. It is obviously wrong.

Give it up already. Propose a modification to the
C language to the standards committee. Bitching about
it is just noise.

Re: Effect of CPP tags

<slrnupeb0t.qme.jj@iridium.wf32df>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30604&group=comp.lang.c#30604

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jj...@franjam.org.uk (Jim Jackson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 22:07:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <slrnupeb0t.qme.jj@iridium.wf32df>
References: <umet9d$3hir9$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <%cFlN.140487$xHn7.115393@fx14.iad>
Injection-Date: Thu, 4 Jan 2024 22:07:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ac6a0fd152d5efb5d37fa882d2f8bf2e";
logging-data="4003787"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ePESlbyueVQAzwvozD0RN1fmFSiS3XsY="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:N1EyQghx/vbbfrIVpOph1Jqzq2Y=
 by: Jim Jackson - Thu, 4 Jan 2024 22:07 UTC

On 2024-01-04, Scott Lurndal <scott@slp53.sl.home> wrote:
> Bart <bc@freeuk.cm> writes:
>>
>>This compiles fine.
>
> So what? Any programmer will see that they don't
> match immediately. It is obviously wrong.
>
> Give it up already. Propose a modification to the
> C language to the standards committee. Bitching about
> it is just noise.

Oh boy and isn't there a lot of it - yawn!!!!!

I admire the preserverance

Re: Effect of CPP tags

<un7c2g$3qeu6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30605&group=comp.lang.c#30605

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 17:39:11 -0500
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <un7c2g$3qeu6$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umlba2$iq0h$3@dont-email.me>
<ummhnp$rf7k$1@dont-email.me> <ummmqe$s4od$1@dont-email.me>
<87o7e8voy1.fsf@nosuchdomain.example.com> <20231229122012.850@kylheku.com>
<umnhtf$103sg$1@dont-email.me> <ums14k$1p0rs$1@dont-email.me>
<umsnbn$1ro5b$7@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un42nr$38vqs$1@dont-email.me>
<87il4at7pf.fsf@nosuchdomain.example.com> <un65po$3l03p$1@dont-email.me>
<un68qj$3lbuq$1@dont-email.me> <un6r6m$3nsfu$2@dont-email.me>
<un6svh$3o7pk$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 4 Jan 2024 22:39:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ac97f9a6e8e328f641d7c08ef6026495";
logging-data="4012998"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/D7YhAp/JEkJLci8OQyBHY8FnyoqmEcug="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:52rI8UklZ39Bo7c2yVAMb1WMwQw=
Content-Language: en-US
In-Reply-To: <un6svh$3o7pk$1@dont-email.me>
 by: James Kuyper - Thu, 4 Jan 2024 22:39 UTC

On 1/4/24 13:21, Bart wrote:
> On 04/01/2024 17:51, James Kuyper wrote:
....
>> You don't consider it distracting that void* makes it a constraint
>> violation, rendering the behavior of any program that uses such code
>> undeifined?
>
> Only to people obsessed with Standards minutiae.

These "standards minutae" mean that a conforming implementation of C has
no obligation to produce any particular kind of behavior for such code.
If you don't care what kind of behavior your code has, why write a new
program? Take any existing program - whatever behavior that existing
program has, is one of the behaviors that an implementation is allowed
to produce when translating your new program. Since you've declared, by
deliberately using such code, that you don't care whether it produces
such behavior, using the existing program should be fine.

Re: Effect of CPP tags

<un7cjh$3qi9d$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30606&group=comp.lang.c#30606

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.cm (Bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 22:48:17 +0000
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <un7cjh$3qi9d$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <%cFlN.140487$xHn7.115393@fx14.iad>
<slrnupeb0t.qme.jj@iridium.wf32df>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 4 Jan 2024 22:48:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b2b9baa6625c35c2e3f0e524f125ac00";
logging-data="4016429"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nw/fFgVLY8bWk067xydjUHEIIoM0xvMU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:gKK1rZrjwMleFFQlOzAvhoLkoeQ=
In-Reply-To: <slrnupeb0t.qme.jj@iridium.wf32df>
Content-Language: en-GB
 by: Bart - Thu, 4 Jan 2024 22:48 UTC

On 04/01/2024 22:07, Jim Jackson wrote:
> On 2024-01-04, Scott Lurndal <scott@slp53.sl.home> wrote:
>> Bart <bc@freeuk.cm> writes:
>>>
>>> This compiles fine.
>>
>> So what? Any programmer will see that they don't
>> match immediately. It is obviously wrong.
>>
>> Give it up already. Propose a modification to the
>> C language to the standards committee. Bitching about
>> it is just noise.
>
> Oh boy and isn't there a lot of it - yawn!!!!!
>
> I admire the preserverance

For 40 years 99% of my coding has been in a language where you just write:

A.len

instead of:

sizeof(A)/size(A[0])

So it's no skin off my nose if you prefer to do that or are happy
reinventing various workarounds.

I had wondered if things would have been any different without macros to
create those workarounds.

It looks like, probably not.

So, /I/ admire your stoicism in putting up with a badly designed
language of which this is one tiny aspect.

(Tell me, if /you/ were to design a new language, would you still
require that sizeof/sizeof business? No? Thought not!)

Re: Effect of CPP tags

<20240104151249.990@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30607&group=comp.lang.c#30607

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 23:14:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <20240104151249.990@kylheku.com>
References: <umet9d$3hir9$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <%cFlN.140487$xHn7.115393@fx14.iad>
<slrnupeb0t.qme.jj@iridium.wf32df> <un7cjh$3qi9d$1@dont-email.me>
Injection-Date: Thu, 4 Jan 2024 23:14:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="624dae6c469856f06c49a782a2b1407e";
logging-data="4021339"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185MJlihutVjIrKe6rPQUqgyj7iKMzQXJQ="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:QtkLx2FkTBCQhyrjQlImsGsy9bE=
 by: Kaz Kylheku - Thu, 4 Jan 2024 23:14 UTC

On 2024-01-04, Bart <bc@freeuk.cm> wrote:
> On 04/01/2024 22:07, Jim Jackson wrote:
>> On 2024-01-04, Scott Lurndal <scott@slp53.sl.home> wrote:
>>> Bart <bc@freeuk.cm> writes:
>>>>
>>>> This compiles fine.
>>>
>>> So what? Any programmer will see that they don't
>>> match immediately. It is obviously wrong.
>>>
>>> Give it up already. Propose a modification to the
>>> C language to the standards committee. Bitching about
>>> it is just noise.
>>
>> Oh boy and isn't there a lot of it - yawn!!!!!
>>
>> I admire the preserverance
>
> For 40 years 99% of my coding has been in a language where you just write:
>
> A.len
>
> instead of:
>
> sizeof(A)/size(A[0])

But I suspect that language can pass the array to a function, and
that function also do A.len, right?

Even when we have a macro or language extension that calculates
sizeof(A)/sizeof(*A), it is only usable for arrays that were not passed
by pointer.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Effect of CPP tags

<875y08u1il.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30608&group=comp.lang.c#30608

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 04 Jan 2024 15:22:58 -0800
Organization: None to speak of
Lines: 77
Message-ID: <875y08u1il.fsf@nosuchdomain.example.com>
References: <umet9d$3hir9$1@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <un72f1$3p72u$1@dont-email.me>
<un73om$3pd33$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4d95b7a32aae07de52f424985a97135f";
logging-data="4025053"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ebThja0w6epkdywhaZyz+"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:f2TBQx9IGQSwmEegzbiiOurCEfk=
sha1:bRTw9pt5bWASC5pCw2LBytczZnQ=
 by: Keith Thompson - Thu, 4 Jan 2024 23:22 UTC

Bart <bc@freeuk.cm> writes:
> On 04/01/2024 19:55, Janis Papanagnou wrote:
>> On 04.01.2024 19:35, Bart wrote:
>>>
>>> Now look at the basketcase that is C's attempt. C could EASILY have had
>>> an equivalent op that works like 'size'of'; it chose not to.
>> You're asking for an, say, 'nof_elements(A)', where there's
>> currently
>> only a 'sizeof(A)/sizeof(A[0])' existing? - Is that the whole resume
>> of this overly bulky subthread?
>
> Yes exactly.
>
> If you're arguing that it is such a trivial matter that it is hardly
> worth discussing, I can equally say that if it is that trivial, why
> isn't it just built-in? How hard can it be?

Implementing a new "lengthof" macro in an existing implementation?
Nearly trivial. (I picked the name for vague consistency with sizeof
and alignof.)

Implementing it in such a way that it can't easily be misused on an
argument of pointer type? A little harder, but I think solutions exist,
and it only has to be written once.

Implementing it as an operator, similar to sizeof and alignof?
Feasible, probably not a whole lot of work for each compiler. All
compilers implement sizeof, so all the information needed to implement
lengthof is already available -- and applying it to something that's a
pointer rather than array could be a constraint violation.

Standardizing it? Getting agreement on a name that (a) makes its
meaning clear and (b) doesn't conflict with existing code? (Or getting
agreement that breaking *some* existing code is acceptable?) Ensuring
that the specification covers all corner cases? Documenting it with
accuracy and precision comparable to other existing wording in the
standard? Reviewing that documentation and replying to complaints, some
valid, some not? Getting it into the next edition of the C standard and
getting all conforming implementations to provide it? Possible, but not
at all easy.

Demonstrating that there's enough demand to justify all this effort?
Explaining why the existing situation (individual programs either
defining their own macros or writing the expression inline and going to
some effort to ensure that such code, like all the other code, is
correct) is not good enough? Demonstrating that the current situation
actually causes serious problems? Not easy at all.

Any C implementation can provide such a macro as an extension. An
implementation could, for example, define a macro lengthof() in
<stddef.h>. I haven't checked, but I don't believe it does so, most
likely because few if any users have asked for it.

Nobody is claiming that C is a perfect language. If it had provided,
starting in C89, a built-in lengthof similar to sizeof, that would have
been fine and dandy. But the lack of such an operator has not been a
big enough problem to justify the *substantial* effort a universal
solution would require. There are a whole lot of nice-to-have features
that aren't in the language simply because they weren't part of the
language to begin with.

Sure, two software projects could use different names, and there could
be problems when merging code from them. Such problems can always occur
anyway, for a number of reasons. And such problems are solvable.

Note that most array objects are dealt with via pointers. Once you pass
an array to a function, the function sees it as a pointer, and *cannot*
determine how many elements it has. The feature you want could only be
used for an array object that's defined at block scope (local to a
function) or at file scope (outside any function).

[snip]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Effect of CPP tags

<un7eoj$3qpmp$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30609&group=comp.lang.c#30609

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.bbs.nz!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 23:25:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <un7eoj$3qpmp$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <%cFlN.140487$xHn7.115393@fx14.iad>
<slrnupeb0t.qme.jj@iridium.wf32df> <un7cjh$3qi9d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 4 Jan 2024 23:25:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e86eefbb5c47a726a6c35183164fc57f";
logging-data="4024025"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XbUkgfeKNf6SPPMiYHEKI"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:z+yHxw84jHVe3ybPI8HuVGGM74k=
 by: Lawrence D'Oliv - Thu, 4 Jan 2024 23:25 UTC

On Thu, 4 Jan 2024 22:48:17 +0000, Bart wrote:

> For 40 years 99% of my coding has been in a language where you just
> write:
>
> A.len

Better still:

len(A)

which is just a generic wrapper around

A.__len__()

so it will work with your custom object types as well, all they have to do
is define a method with that name.

Re: Effect of CPP tags

<un7g3i$3r08q$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30610&group=comp.lang.c#30610

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.cm (Bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Thu, 4 Jan 2024 23:48:02 +0000
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <un7g3i$3r08q$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <%cFlN.140487$xHn7.115393@fx14.iad>
<slrnupeb0t.qme.jj@iridium.wf32df> <un7cjh$3qi9d$1@dont-email.me>
<20240104151249.990@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 4 Jan 2024 23:48:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="de412a63226b1270d33da06065ff1dc3";
logging-data="4030746"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Om6GACwzePeyLI3QER8zUjAcvr9EIajQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:/ypuUAE+TuV0fxbyJKhdNvk8+Zk=
Content-Language: en-GB
In-Reply-To: <20240104151249.990@kylheku.com>
 by: Bart - Thu, 4 Jan 2024 23:48 UTC

On 04/01/2024 23:14, Kaz Kylheku wrote:
> On 2024-01-04, Bart <bc@freeuk.cm> wrote:
>> On 04/01/2024 22:07, Jim Jackson wrote:

>>> I admire the preserverance
>>
>> For 40 years 99% of my coding has been in a language where you just write:
>>
>> A.len
>>
>> instead of:
>>
>> sizeof(A)/size(A[0])
>
> But I suspect that language can pass the array to a function, and
> that function also do A.len, right?

That depends. If the length is part of the type like in these 3
examples, then yes:

proc F1([5]int A) = println A.len end # by 'value'

proc F2(ref[5]int P) = println P.len end # by pointer**

proc F3([5]int &A) = println A.len end # by reference

(** It auto-derefs.) But it can only be called with an array of that
exact size:

[5]int A
[7]int B

F1(A)
F2(&A)
F3(A)

I can use A, but not B.

However most arrays passed to functions are unbounded (use [] not [N]),
since it is most useful to allow arrays of arbitrary length (this was
the problem with the first Pascals) then you will need a separate length
parameter.

Attempting A.len when A has type []int will give 0.

Alternately, slices can be used which carry their length:

proc F4(slice[]int S) = println S.len end

Now I can call it with both A and B, and without needing a separate length:

F4(A)
F4(B)

Or with a slice of an array:

F4(B[3..5]) # displays 3, but the bounds are 1..3

> Even when we have a macro or language extension that calculates
> sizeof(A)/sizeof(*A), it is only usable for arrays that were not passed
> by pointer.

The test lengthof(A) implementation which I did in 20 minutes the other
day, doesn't report an error when A is not an array; it just ignores it
and does sizeof(). So it will take bit longer to make it robust.

Re: Effect of CPP tags

<un7ndt$3rr75$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30611&group=comp.lang.c#30611

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.cm (Bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 5 Jan 2024 01:53:00 +0000
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <un7ndt$3rr75$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <%cFlN.140487$xHn7.115393@fx14.iad>
<slrnupeb0t.qme.jj@iridium.wf32df> <un7cjh$3qi9d$1@dont-email.me>
<un7eoj$3qpmp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 5 Jan 2024 01:53:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="de412a63226b1270d33da06065ff1dc3";
logging-data="4058341"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18g8ra6ZgzTMUh7Ba0HOP31zdB3HGn1wfA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:FUynj9t6P/umVmy91Ybyd2VIJy4=
Content-Language: en-GB
In-Reply-To: <un7eoj$3qpmp$1@dont-email.me>
 by: Bart - Fri, 5 Jan 2024 01:53 UTC

On 04/01/2024 23:25, Lawrence D'Oliveiro wrote:
> On Thu, 4 Jan 2024 22:48:17 +0000, Bart wrote:
>
>> For 40 years 99% of my coding has been in a language where you just
>> write:
>>
>> A.len
>
> Better still:
>
> len(A)
>
> which is just a generic wrapper around
>
> A.__len__()
>
> so it will work with your custom object types as well, all they have to do
> is define a method with that name.

If a language has a built-in like A.len or len(A) or A'len and so on,
then it can choose to allow overloading for that operator. The syntax
chosen doesn't matter.

It doesn't need to take a heavy-handed approach like C++ or Python.

Re: Effect of CPP tags

<un820p$l6e$6@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30612&group=comp.lang.c#30612

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 5 Jan 2024 04:53:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <un820p$l6e$6@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <%cFlN.140487$xHn7.115393@fx14.iad>
<slrnupeb0t.qme.jj@iridium.wf32df> <un7cjh$3qi9d$1@dont-email.me>
<un7eoj$3qpmp$1@dont-email.me> <un7ndt$3rr75$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 5 Jan 2024 04:53:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e86eefbb5c47a726a6c35183164fc57f";
logging-data="21710"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+F46i7BthIxSuqdkdeXxsR"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:kNdhwjiKiiJYiENEALvTzC2yGYA=
 by: Lawrence D'Oliv - Fri, 5 Jan 2024 04:53 UTC

On Fri, 5 Jan 2024 01:53:00 +0000, Bart wrote:

> If a language has a built-in like A.len or len(A) or A'len and so on,
> then it can choose to allow overloading for that operator. The syntax
> chosen doesn't matter.

The operation still has to be defined for the relevant type, in order for
the construct to work.

> It doesn't need to take a heavy-handed approach like C++ or Python.

Given that the entire Python language definition is a small fraction of
that of, say, Java, which does not allow operator overloading on user-
defined types, I would hardly describe it as “heavy-handed”.

Re: Effect of CPP tags

<un8gkp$3ne6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30613&group=comp.lang.c#30613

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!nntp.comgw.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 5 Jan 2024 10:03:20 +0100
Organization: A noiseless patient Spider
Lines: 107
Message-ID: <un8gkp$3ne6$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <umuj4q$28384$1@dont-email.me>
<umun7n$28l7q$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <un72f1$3p72u$1@dont-email.me>
<un73om$3pd33$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 5 Jan 2024 09:03:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="080dde8912c81f3aee97f1c05bc0f4dc";
logging-data="122310"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19E3kSivuwhdloQekoi3sBD"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:Zc0bPcS1zeMaFZqsZcmBpOiyPDw=
In-Reply-To: <un73om$3pd33$1@dont-email.me>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Fri, 5 Jan 2024 09:03 UTC

On 04.01.2024 21:17, Bart wrote:
> On 04/01/2024 19:55, Janis Papanagnou wrote:
>> On 04.01.2024 19:35, Bart wrote:
>>>
>>> Now look at the basketcase that is C's attempt. C could EASILY have had
>>> an equivalent op that works like 'size'of'; it chose not to.
>>
>> You're asking for an, say, 'nof_elements(A)', where there's currently
>> only a 'sizeof(A)/sizeof(A[0])' existing? - Is that the whole resume
>> of this overly bulky subthread?
>
> Yes exactly.

Fine.

>
> If you're arguing that it is such a trivial matter that it is hardly
> worth discussing, I can equally say that if it is that trivial, why
> isn't it just built-in? How hard can it be?

Why so paranoid defensive? :-) I wasn't arguing (not yet), I was asking
two questions; one was what appears to be the essence of thousands lines
of posts with a lot repetitions. (And the other was on the posting meta
level, with the implicit hope to come to an end since everything seems
to have been said on that theme.) Also the two questions you have added
here (seemingly as virtual counter-argument) had already been addressed.

>
> The subthread was actually about the macro system, and this example was
> one I gave where macros make it possible for every man and his dog to
> create their own sloppy, incompatible workaround.

I'm sure I already read arguments on that many times in this thread. My
view is that all the programming areas create (also sloppy) workarounds
for features that are not part of the "language of choice" (here: "C").

Specifically when discussing C there's IMO countless examples of what's
missing, and what's wrongly designed, and whatnot. - Thus I am merely
astonished that you fastened on that bit so vigorously, and also with
so much text and repetitions.

>
> Every other app seems to provide their own version; I gave three where
> so far we have ArraySize, SDL_arraysize, and ARRAY_SIZE.
>
> You yourself have suggested 'nof_elements'. You see the problem?

Not the least. The sizeof/sizeof I consider as an idiomatic approach
to achieve for a special detail of the language a practical solution.

And the naming of entities in programs through identifiers will always
be individual, while in practice typically with semantically sensible
naming. I really don't care if programmers call her entities X or Y.
Only if a language designer (or committee) decides to add a feature as
a standard part of the language it becomes important.

There's (IMO) so much wrong with arrays in C that the discussed special
case (which is also not generally applicable as pointed out repeatedly)
is of little interest (for me; YMMV).

>
> I'm not actually too bothered about that (I know C is never going to
> have anything that is that sensible), I'm arguing against attitudes like
> yours that it doesn't matter.

Yet - despite dozens of posts with thousands of lines - I haven't seen
any convincing argument that it would matter.

>
> My original point may have been this: suppose C's macro system didn't
> exist. Would that have given enough impetus to whoever was or were
> responsible for the language, to actually do it properly?

That's a noteworthy statement since formulated as thought experiment.
But the hypothetical precondition shows that it's really not worth a
discussion in the first place.

Mind, I started with K&R C in the 1980's, at a time where much more
sophisticated languages had already been present; the formally much
more appealing Algol(68), the concepts-outstanding Simula(67), even
Pascal (that you recently also mentioned) was very appealing due to
its simplicity, efficiency, expressiveness and still clearness, just
to name a few. What I was missing in C - one major issue was the OO
capabilities that I had got used with Simula - I later found in C++,
alongside with the efficiency of C inherited, but also with all the
deficiencies of C; but for some features you've got alternatives
(e.g. sophisticated STL containers replacing these (IMO annoying)
low-level "C arrays" (with all its inhomogeneities), and providing
yet much more that I appreciated).

>
> Since my conjecture was that C's macro scheme stopped it evolving normally.

Above we identified a "resume" of the previous posts. Another one
shall finalize this post; no one is forced to use C. - Myself I'm
using it occasionally where appropriate. But if I think something
is in my way - and may it be only as unimportant as 'A.length' -
I'll just switch to another language (with richer feature set, or
with a more coherent design). It certainly wouldn't occur to me to
ask for features that I already find in many contemporary language
I can choose from.

I'm confident your mileage may vary, and we can agree to disagree.
:-)

Janis

Re: Effect of CPP tags

<un92c7$6325$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30614&group=comp.lang.c#30614

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 5 Jan 2024 15:05:59 +0100
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <un92c7$6325$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <%cFlN.140487$xHn7.115393@fx14.iad>
<slrnupeb0t.qme.jj@iridium.wf32df> <un7cjh$3qi9d$1@dont-email.me>
<un7eoj$3qpmp$1@dont-email.me> <un7ndt$3rr75$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 5 Jan 2024 14:05:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d5f950065253521c024e28ae053c5667";
logging-data="199749"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GfRo+1TAwvJ6H38/rOj/skHt3eoGoqds="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:B/3rDc4V0zdOcQ8hl6CeWCvDfe4=
In-Reply-To: <un7ndt$3rr75$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Fri, 5 Jan 2024 14:05 UTC

On 05/01/2024 02:53, Bart wrote:
> On 04/01/2024 23:25, Lawrence D'Oliveiro wrote:
>> On Thu, 4 Jan 2024 22:48:17 +0000, Bart wrote:
>>
>>> For 40 years 99% of my coding has been in a language where you just
>>> write:
>>>
>>>       A.len
>>
>> Better still:
>>
>>      len(A)
>>
>> which is just a generic wrapper around
>>
>>      A.__len__()
>>
>> so it will work with your custom object types as well, all they have
>> to do
>> is define a method with that name.
>
> If a language has a built-in like A.len or len(A) or A'len and so on,
> then it can choose to allow overloading for that operator. The syntax
> chosen doesn't matter.
>
> It doesn't need to take a heavy-handed approach like C++ or Python.
>

One option for a useful array length operator/function/macro is a simple
and limited feature that works for arrays of known size and gives a hard
(compile-time) error when the size is not known. The one you have in
your own language covers most of that, except for the insanity of
evaluating to 0 when given a pointer/reference to an "unbounded" array.
The "ARRAY_SIZE" macro in Linux is almost perfect - the only
disadvantage is that it relies on compiler extensions:

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) +
__must_be_array(arr))

#define __same_type(a, b) __builtin_types_compatible_p(typeof(a),
typeof(b)))

#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))

#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))

The other option is a general mechanism for "length" as an
operator/function/macro that can be applied to a wide range of types -
including user-made types, assuming the language supports user-defined
types. Whether that is done by function overloads, custom methods,
etc., is a design choice.

Re: Effect of CPP tags

<mDVlN.135110$p%Mb.121089@fx15.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30615&group=comp.lang.c#30615

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx15.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Effect of CPP tags
Newsgroups: comp.lang.c
References: <umet9d$3hir9$1@dont-email.me> <un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad> <un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me> <un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad> <un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad> <un6toq$3ogqm$1@dont-email.me> <%cFlN.140487$xHn7.115393@fx14.iad> <slrnupeb0t.qme.jj@iridium.wf32df> <un7cjh$3qi9d$1@dont-email.me> <un7eoj$3qpmp$1@dont-email.me> <un7ndt$3rr75$1@dont-email.me>
Lines: 24
Message-ID: <mDVlN.135110$p%Mb.121089@fx15.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 05 Jan 2024 15:54:58 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 05 Jan 2024 15:54:58 GMT
X-Received-Bytes: 1631
 by: Scott Lurndal - Fri, 5 Jan 2024 15:54 UTC

Bart <bc@freeuk.cm> writes:
>On 04/01/2024 23:25, Lawrence D'Oliveiro wrote:
>> On Thu, 4 Jan 2024 22:48:17 +0000, Bart wrote:
>>
>>> For 40 years 99% of my coding has been in a language where you just
>>> write:
>>>
>>> A.len
>>
>> Better still:
>>
>> len(A)
>>
>> which is just a generic wrapper around
>>
>> A.__len__()
>>
>> so it will work with your custom object types as well, all they have to do
>> is define a method with that name.
>
>If a language has a built-in

The C language doesn't have such a built-in. Any discussion that
assumes it does, or will, is pointless.

Re: Effect of CPP tags

<871qavu5z9.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30616&group=comp.lang.c#30616

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 05 Jan 2024 07:58:50 -0800
Organization: None to speak of
Lines: 32
Message-ID: <871qavu5z9.fsf@nosuchdomain.example.com>
References: <umet9d$3hir9$1@dont-email.me> <un0pb2$2kp7q$1@dont-email.me>
<un1clg$2oq9u$1@dont-email.me> <un1hek$2ph62$1@dont-email.me>
<un1rdk$2quec$1@dont-email.me> <un25vp$1qvm$1@news.gegeweb.eu>
<un3hvm$36jtf$1@dont-email.me> <Z5flN.88873$vFZa.33923@fx13.iad>
<un44ln$398sl$1@dont-email.me> <un4bq2$3a8kc$1@dont-email.me>
<un4ro2$3ce1u$1@dont-email.me> <mgolN.15004$SyNd.1220@fx33.iad>
<un54lv$3ddec$1@dont-email.me> <RJAlN.141573$c3Ea.132913@fx10.iad>
<un6toq$3ogqm$1@dont-email.me> <%cFlN.140487$xHn7.115393@fx14.iad>
<slrnupeb0t.qme.jj@iridium.wf32df> <un7cjh$3qi9d$1@dont-email.me>
<un7eoj$3qpmp$1@dont-email.me> <un7ndt$3rr75$1@dont-email.me>
<un92c7$6325$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4d95b7a32aae07de52f424985a97135f";
logging-data="230198"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fJYXZWJViAuZHwu8Qj399"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:1KT50f/Qkyx8zEZ5k+SA91ZSlTY=
sha1:MBiTSQC3AHjE/u3dRJw3DbXeF1Y=
 by: Keith Thompson - Fri, 5 Jan 2024 15:58 UTC

David Brown <david.brown@hesbynett.no> writes:
[...]
> One option for a useful array length operator/function/macro is a
> simple and limited feature that works for arrays of known size and
> gives a hard (compile-time) error when the size is not known. The one
> you have in your own language covers most of that, except for the
> insanity of evaluating to 0 when given a pointer/reference to an
> "unbounded" array. The "ARRAY_SIZE" macro in Linux is almost perfect -
> the only disadvantage is that it relies on compiler extensions:
>
> #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) +
> __must_be_array(arr))
>
> #define __same_type(a, b) __builtin_types_compatible_p(typeof(a),
> typeof(b)))
>
> #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
>
> #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
[...]

When you wrote "in Linux", I wondered if you were being imprecise, but
in fact that code is in the Linux kernel.

That means the macros aren't directly available to normal C code, but
you can always copy their definitions (*if* you're using a compiler
that supports the __builtin_types_compatible_p extension).

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Effect of CPP tags

<un9ae2$77ft$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=30617&group=comp.lang.c#30617

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.cm (Bart)
Newsgroups: comp.lang.c
Subject: Re: Effect of CPP tags
Date: Fri, 5 Jan 2024 16:23:30 +0000
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <un9ae2$77ft$1@dont-email.me>
References: <umet9d$3hir9$1@dont-email.me> <un3hvm$36jtf$1@dont-email.me>
<Z5flN.88873$vFZa.33923@fx13.iad> <un44ln$398sl$1@dont-email.me>
<un4bq2$3a8kc$1@dont-email.me> <un4ro2$3ce1u$1@dont-email.me>
<mgolN.15004$SyNd.1220@fx33.iad> <un54lv$3ddec$1@dont-email.me>
<RJAlN.141573$c3Ea.132913@fx10.iad> <un6toq$3ogqm$1@dont-email.me>
<%cFlN.140487$xHn7.115393@fx14.iad> <slrnupeb0t.qme.jj@iridium.wf32df>
<un7cjh$3qi9d$1@dont-email.me> <un7eoj$3qpmp$1@dont-email.me>
<un7ndt$3rr75$1@dont-email.me> <mDVlN.135110$p%Mb.121089@fx15.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 5 Jan 2024 16:23:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="de412a63226b1270d33da06065ff1dc3";
logging-data="237053"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Z0y87tQxUy9W+GJNsGlEuI/+IPyBxbDk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:lzi2mqVYrNV/GB2k5UcjwCBjrtg=
Content-Language: en-GB
In-Reply-To: <mDVlN.135110$p%Mb.121089@fx15.iad>
 by: Bart - Fri, 5 Jan 2024 16:23 UTC

On 05/01/2024 15:54, Scott Lurndal wrote:
> Bart <bc@freeuk.cm> writes:
>> On 04/01/2024 23:25, Lawrence D'Oliveiro wrote:
>>> On Thu, 4 Jan 2024 22:48:17 +0000, Bart wrote:
>>>
>>>> For 40 years 99% of my coding has been in a language where you just
>>>> write:
>>>>
>>>> A.len
>>>
>>> Better still:
>>>
>>> len(A)
>>>
>>> which is just a generic wrapper around
>>>
>>> A.__len__()
>>>
>>> so it will work with your custom object types as well, all they have to do
>>> is define a method with that name.
>>
>> If a language has a built-in
>
> The C language doesn't have such a built-in. Any discussion that
> assumes it does, or will, is pointless.

It could be an extension.

I assume none of your code uses extensions to standard C? Not even
inline assembly?


devel / comp.lang.c / Re: Effect of CPP tags

Pages:123456789101112131415161718192021222324252627
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor