Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Harrison's Postulate: For every action, there is an equal and opposite criticism.


devel / comp.lang.c++ / “ChattyG takes a college freshman C/C++ programming exam”

SubjectAuthor
* “ChattyG takes a college freshman C/C++ programmiLynn McGuire
+- Re: “ChattyG takes a college freshman C/C++ proChris M. Thomasson
+* Re: “ChattyG takes a college freshman C/C++ proChristian Gollwitzer
|`- Re: “ChattyG takes a college freshman C/C++ proChris M. Thomasson
+* Re: “ChattyG takes a college freshman C/C++Anton Shepelev
|`* Re: “ChattyG takes a college freshman C/C++ progrjak
| +- Re: “ChattyG takes a college freshman C/C++ proJames Kuyper
| +* Re: “ChattyG takes a college freshman C/C++Anton Shepelev
| |+- Re: “ChattyG takes a college freshman C/C++Anton Shepelev
| |+* Re: “ChattyG takes a college freshman C/C++ procandycanearter07
| ||+* Re: “ChattyG takes a college freshman C/C++Anton Shepelev
| |||`* Re: “ChattyG takes a college freshman C/C++ progrPavel
| ||| +- Re: “ChattyG takes a college freshman C/C++ proRichard Damon
| ||| `* Re: “ChattyG takes a college freshman C/C++ proJames Kuyper
| |||  `* Re: “ChattyG takes a college freshman C/C++ progrPavel
| |||   +- Re: “ChattyG takes a college freshman C/C++ proRichard Damon
| |||   `- Re: “ChattyG takes a college freshman C/C++ proJames Kuyper
| ||`* Re: “ChattyG takes a college freshman C/C++ proChris M. Thomasson
| || +* Re: “ChattyG takes a college freshman C/C++ proRichard Damon
| || |`* Re: “ChattyG takes a college freshman C/C++ proJames Kuyper
| || | `- Re: “ChattyG takes a college freshman C/C++ proChris M. Thomasson
| || `* Re: “ChattyG takes a college freshman C/C++ proMarioCCCP
| ||  `- Re: “ChattyG takes a college freshman C/C++Keith Thompson
| |+- Re: “ChattyG takes a college freshman C/C++Ben Bacarisse
| |+* Re: “ChattyG takes a college freshman C/C++ proJames Kuyper
| ||`- Re: “ChattyG takes a college freshman C/C++Anton Shepelev
| |`* Re: “ChattyG takes a college freshman C/C++Blue-Maned_Hawk
| | +* Re: “ChattyG takes a college freshman C/C++Anton Shepelev
| | |+* Re: “ChattyG takes a college freshman C/C++ proJames Kuyper
| | ||`* Re: “ChattyG takes a college freshman C/C++ proChris M. Thomasson
| | || `* Re: Re: “ChattyG takes a college freshman C/C++ programming exam”Scott Lurndal
| | ||  `- Re: “ChattyG takes a college freshman C/C++ proChris M. Thomasson
| | |`* Re: “ChattyG takes a college freshman C/C++Blue-Maned_Hawk
| | | `* Re: “ChattyG takes a college freshman C/C++Anton Shepelev
| | |  +* Re: “ChattyG takes a college freshman C/C++ programming exam”Scott Lurndal
| | |  |`* Re: “ChattyG takes a college freshman C/C++Anton Shepelev
| | |  | +- Re: “ChattyG takes a college freshman C/C++ programming exam”Scott Lurndal
| | |  | +- Re: “ChattyG takes a college freshman C/C++ programming exam”Scott Lurndal
| | |  | `- Re: “ChattyG takes a college freshman C/C++ proJames Kuyper
| | |  `- Re: “ChattyG takes a college freshman C/C++Ben Bacarisse
| | `* Re: “ChattyG takes a college freshman C/C++Keith Thompson
| |  +* Re: “ChattyG takes a college freshman C/C++ proJames Kuyper
| |  |`* Re: “ChattyG takes a college freshman C/C++Keith Thompson
| |  | +- Re: “ChattyG takes a college freshman C/C++ proJames Kuyper
| |  | +- Re: “ChattyG takes a college freshman C/C++ programming exam”Scott Lurndal
| |  | `- Re: “ChattyG takes a college freshman C/C++Tim Rentsch
| |  `* Re: “ChattyG takes a college freshman C/C++Anton Shepelev
| |   `- Re: “ChattyG takes a college freshman C/C++Keith Thompson
| `- Re: “ChattyG takes a college freshman C/C++ proJames Kuyper
+* Re: “ChattyG takes a college freshman C/C++ proChris M. Thomasson
|+- Re: “ChattyG takes a college freshman C/C++ proChris M. Thomasson
|+- Re: “ChattyG takes a college freshman C/C++Anton Shepelev
|`* Re: “ChattyG takes a college freshman C/C++Anton Shepelev
| `- Re: “ChattyG takes a college freshman C/C++ proChris M. Thomasson
`* Re: “ChattyG takes a college freshman C/C++Anton Shepelev
 `* Re: “ChattyG takes a college freshman C/C++Phil Carmody
  `* Re: “ChattyG takes a college freshman C/C++Anton Shepelev
   `- Re: “ChattyG takes a college freshman C/C++Phil Carmody

Pages:123
“ChattyG takes a college freshman C/C++ programming exam”

<ufne0r$15ple$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2083&group=comp.lang.c%2B%2B#2083

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lynnmcguire5@gmail.com (Lynn McGuire)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: “ChattyG_takes_a_college_freshman_C/C++_programmi
ng_exam”
Date: Thu, 5 Oct 2023 17:40:27 -0500
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <ufne0r$15ple$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 5 Oct 2023 22:40:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3ee43b4d597b03d076430338b6ee12d0";
logging-data="1238702"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1fZAqAafR+cKDedN/eo57t1rNUh9NWg4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CgjS0/QFp++7uoQw5ByWUBUIixg=
Content-Language: en-US
 by: Lynn McGuire - Thu, 5 Oct 2023 22:40 UTC

“ChattyG takes a college freshman C/C++ programming exam”
https://www.theregister.com/2023/10/03/chatgpt_code_college/

“ChatGPT was put to the test via a series of humdrum freshman C/C++
programming tasks and it passed – though not with honors.”

“According to a Croatian research team, while first-year students can
struggle with some of the assignments, the results [PDF] showed ChatGPT
hitting proficiency targets that ranged between average and that of
experienced programmers. And naturally, as with all college exams,
outcomes can be determined by how questions are worded.”

Lynn

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ufnf1b$15tsq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2084&group=comp.lang.c%2B%2B#2084

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Thu, 5 Oct 2023 15:57:46 -0700
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <ufnf1b$15tsq$1@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 5 Oct 2023 22:57:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cc58f85c75e2a3f0e82b5349446f8c23";
logging-data="1243034"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7wL0ktIoP0prVGLQL4g+57ljXR5WUuLg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:HKyDfdQYYNe6/WSI+pinOToqt4g=
In-Reply-To: <ufne0r$15ple$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Thu, 5 Oct 2023 22:57 UTC

On 10/5/2023 3:40 PM, Lynn McGuire wrote:
> “ChattyG takes a college freshman C/C++ programming exam”
>    https://www.theregister.com/2023/10/03/chatgpt_code_college/
>
> “ChatGPT was put to the test via a series of humdrum freshman C/C++
> programming tasks and it passed – though not with honors.”
>
> “According to a Croatian research team, while first-year students can
> struggle with some of the assignments, the results [PDF] showed ChatGPT
> hitting proficiency targets that ranged between average and that of
> experienced programmers. And naturally, as with all college exams,
> outcomes can be determined by how questions are worded.”

If we keep teaching it, it should get better and better... :^o

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ufo6fb$1ddit$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2086&group=comp.lang.c%2B%2B#2086

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: auriocus@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Fri, 6 Oct 2023 07:36:07 +0200
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <ufo6fb$1ddit$1@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 6 Oct 2023 05:37:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="817b36916e0a3ff7c49cbcde41c76c5a";
logging-data="1488477"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dkdRAOt3v1rC21So2VHyStIZm4q2dsd8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:1+0Sny+1BxN6vRwnZ9PARWWFCws=
In-Reply-To: <ufne0r$15ple$1@dont-email.me>
 by: Christian Gollwitzer - Fri, 6 Oct 2023 05:36 UTC

Am 06.10.23 um 00:40 schrieb Lynn McGuire:
> “ChattyG takes a college freshman C/C++ programming exam”
>    https://www.theregister.com/2023/10/03/chatgpt_code_college/
>
> “ChatGPT was put to the test via a series of humdrum freshman C/C++
> programming tasks and it passed – though not with honors.”

This is already outdated. I've read the paper and they used the free
version, aka GPT-3.5. They should repeat the same tests with at least
GPT-4. There is a vast improvement especially in programming skill from
3.5 to 4.

In addition, there are open source models available which you can run on
your own computer [1], some of them are specifically finetuned towards
coding - e.g. WizardCoder [2]. The version finetuned to Python
specifically is claimed to surpass GPT-4 in some benchmarks. It can be
downloaded in quantized form, ready to run even CPU-only on a machine
with sufficient RAM [1,3]

[1] https://github.com/ggerganov/llama.cpp
[2] https://github.com/nlpxucan/WizardLM/
[3] https://huggingface.co/TheBloke/WizardCoder-Python-34B-V1.0-GGUF

Christian

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ufplfa$1rmlt$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2087&group=comp.lang.c%2B%2B#2087

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Fri, 6 Oct 2023 11:59:54 -0700
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <ufplfa$1rmlt$1@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me> <ufo6fb$1ddit$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 6 Oct 2023 18:59:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cc58f85c75e2a3f0e82b5349446f8c23";
logging-data="1956541"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18MfUWlx2FiTRZcapsXNUV9JC4huRwcXs0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:0ptIqM8CcdX/iRCy10i9f99ObQo=
In-Reply-To: <ufo6fb$1ddit$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 6 Oct 2023 18:59 UTC

On 10/5/2023 10:36 PM, Christian Gollwitzer wrote:
> Am 06.10.23 um 00:40 schrieb Lynn McGuire:
>> “ChattyG takes a college freshman C/C++ programming exam”
>>     https://www.theregister.com/2023/10/03/chatgpt_code_college/
>>
>> “ChatGPT was put to the test via a series of humdrum freshman C/C++
>> programming tasks and it passed – though not with honors.”
>
> This is already outdated. I've read the paper and they used the free
> version, aka GPT-3.5. They should repeat the same tests with at least
> GPT-4. There is a vast improvement especially in programming skill from
> 3.5 to 4.
>
> In addition, there are open source models available which you can run on
> your own computer [1], some of them are specifically finetuned towards
> coding - e.g. WizardCoder [2]. The version finetuned to Python
> specifically is claimed to surpass GPT-4 in some benchmarks. It can be
> downloaded in quantized form, ready to run even CPU-only on a machine
> with sufficient RAM [1,3]
>
> [1] https://github.com/ggerganov/llama.cpp
> [2] https://github.com/nlpxucan/WizardLM/
> [3] https://huggingface.co/TheBloke/WizardCoder-Python-34B-V1.0-GGUF

Thanks for the links. :^)

Re: “ChattyG takes a college freshman C/C++ programming exam”

<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2088&group=comp.lang.c%2B%2B#2088

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton.txt@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Date: Sat, 7 Oct 2023 23:54:48 +0300
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
References: <ufne0r$15ple$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="9d7fdfd6b01c4be7db342d0dc420d4ed";
logging-data="2727996"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Raxw+5YkKeTJ5hgoTlPntHiz3wUa5bME="
Cancel-Lock: sha1:ITVKl/hSbVrSZPXrKk1yCTjWRNQ=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sat, 7 Oct 2023 20:54 UTC

Lynn McGuire:

> ChattyG takes a college freshman C/C++ programming exam
> https://www.theregister.com/2023/10/03/chatgpt_code_college/

For me, it failed the very trivia:

AS: Can a C function return a pointer to itself?

CG: Yes, a C function can return a pointer to itself. This
is known as a recursive function, where a function calls
itself repeatedly until a certain condition is met. In
this case, the function would return a pointer to the
function itself to enable the recursive call.

I asked that question here:

<https://app.chatty-g.com/>
--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: “ChattyG takes a college freshman C/C++ programming exam”

<uftmh9$2vieq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2091&group=comp.lang.c%2B%2B#2091

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@please.ty (jak)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_progr
amming_exam”
Date: Sun, 8 Oct 2023 09:42:32 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <uftmh9$2vieq$1@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 8 Oct 2023 07:42:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f7a98b247a12ac21761ea562205c97af";
logging-data="3131866"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+q/VL/aLUwtSXhlEwXJ0A4"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17.1
Cancel-Lock: sha1:lRnCNDytYuz0IsVZfKK6m6ItjAw=
In-Reply-To: <20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
 by: jak - Sun, 8 Oct 2023 07:42 UTC

Anton Shepelev ha scritto:
> Lynn McGuire:
>
>> ChattyG takes a college freshman C/C++ programming exam
>> https://www.theregister.com/2023/10/03/chatgpt_code_college/
>
> For me, it failed the very trivia:
>
> AS: Can a C function return a pointer to itself?
>
> CG: Yes, a C function can return a pointer to itself. This
> is known as a recursive function, where a function calls
> itself repeatedly until a certain condition is met. In
> this case, the function would return a pointer to the
> function itself to enable the recursive call.
>
> I asked that question here:
>
> <https://app.chatty-g.com/>
>

The explanation is certainly wrong but it is true that it is possible:

#include <stdio.h>

typedef void (* fptr)(int) ;

fptr foo(int n)
{ printf("Call n. %d\n", n);

return (fptr)foo;
}

int main()
{ fptr p = foo(1);

p(2);

return 0;
}

Out:

Call n. 1
Call n. 2

Re: “ChattyG takes a college freshman C/C++ programming exam”

<uftp5s$2vmsp$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2092&group=comp.lang.c%2B%2B#2092

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c++
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Sun, 8 Oct 2023 04:27:39 -0400
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <uftp5s$2vmsp$1@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 8 Oct 2023 08:27:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="895e1a872cd8d1da85552c30102c47a9";
logging-data="3136409"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RhsURO/MikzLCJaqJfj+CXtZXEQL8KA0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:FPKFQDFr807OkfjJmBibuo6eyl8=
In-Reply-To: <uftmh9$2vieq$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Sun, 8 Oct 2023 08:27 UTC

On 10/8/23 03:42, jak wrote:
> Anton Shepelev ha scritto:
>> Lynn McGuire:
>>
>>> ChattyG takes a college freshman C/C++ programming exam
>>> https://www.theregister.com/2023/10/03/chatgpt_code_college/
>>
>> For me, it failed the very trivia:
>>
>> AS: Can a C function return a pointer to itself?
>>
>> CG: Yes, a C function can return a pointer to itself. This
>> is known as a recursive function, where a function calls
>> itself repeatedly until a certain condition is met. In
>> this case, the function would return a pointer to the
>> function itself to enable the recursive call.
>>
>> I asked that question here:
>>
>> <https://app.chatty-g.com/>
>>
>
> The explanation is certainly wrong but it is true that it is possible:
>
> #include <stdio.h>
>
> typedef void (* fptr)(int) ;
>
> fptr foo(int n)
> {
> printf("Call n. %d\n", n);
>
> return (fptr)foo;
> }
>
> int main()
> {
> fptr p = foo(1);
>
> p(2);

The return type of *p is void; the return type of foo is fptr.

"Calling a function through an expression whose function type is
different from the function type of the called
function’s definition results in undefined behavior." (7.6.1.2p6)

Re: “ChattyG takes a college freshman C/C++ programming exam”

<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2093&group=comp.lang.c%2B%2B#2093

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton.txt@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Date: Sun, 8 Oct 2023 12:55:43 +0300
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="367339d4e143f1bde32c26e30c6cb416";
logging-data="3191275"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Wm5/+EaoJpa0Mulgf5aHwMGTRgT7hcaY="
Cancel-Lock: sha1:KP8c6gd9n/oOxLR7rbO6oaHRJcc=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sun, 8 Oct 2023 09:55 UTC

jak to Anton Shepelev:

> > AS: Can a C function return a pointer to itself?
> > CG: Yes, a C function can return a pointer to itself.
>
> The explanation is certainly wrong but it is true that it
> is possible:

I disagree. A function returns the value of its declared
return type. And although C allows the definition of self-
referential structs, it does allow the declaration of self-
referencial functions.

> #include <stdio.h>
>
> typedef void (* fptr)(int) ;
>
> fptr foo(int n)
> {
> printf("Call n. %d\n", n);
> return (fptr)foo;
> }
>
> int main()
> {
> fptr p = foo(1);
> p(2);
> return 0;
> }
>
> Out:
>
> Call n. 1
> Call n. 2

You are converting void to function pointer fptr. This is
not supported in C. You might have taken advantage of
void*, which is silently convertible to any pointer, but
then again it does not work with function pointer, and C has
not analog of void* for functions pointers, so an explicit
conversion is seem inevitable.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: “ChattyG takes a college freshman C/C++ programming exam”

<20231008130608.bc41b2bedd1c1c458a434c75@gmail.moc>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2094&group=comp.lang.c%2B%2B#2094

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton.txt@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Date: Sun, 8 Oct 2023 13:06:08 +0300
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <20231008130608.bc41b2bedd1c1c458a434c75@gmail.moc>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="367339d4e143f1bde32c26e30c6cb416";
logging-data="3191275"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7h/B3P6ZIv8UtR4+2nNMR8bpHy+CZ1WM="
Cancel-Lock: sha1:VKfpBBg/TC5cHywz8YCVt+spdE0=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sun, 8 Oct 2023 10:06 UTC

Anton Shepelev:

> And although C allows the definition of self-referential
> structs, it does allow the declaration of self-referencial
> functions.

does /not/ allow.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ufu3e1$2voq4$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2095&group=comp.lang.c%2B%2B#2095

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no@thanks.net (candycanearter07)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Sun, 8 Oct 2023 06:22:41 -0500
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <ufu3e1$2voq4$2@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 8 Oct 2023 11:22:41 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0f9ed7954820e4bc4412baa00edd3bf1";
logging-data="3138372"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CTN+JnGRYBpp47txl93mRP12/6yJLbkmH91kV8frP9g=="
User-Agent: Betterbird (Linux)
Cancel-Lock: sha1:M8oHwiucpKsLkHeIJ+dj4dDR4wA=
Content-Language: en-US
In-Reply-To: <20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
 by: candycanearter07 - Sun, 8 Oct 2023 11:22 UTC

On 10/8/23 04:55, Anton Shepelev wrote:
> I disagree. A function returns the value of its declared
> return type. And although C allows the definition of self-
> referential structs, it does allow the declaration of self-
> referencial functions.

What if you typedef'd the function pointer?

Also, you could probably get away with it by just setting it to a void
pointer and casting the return value to the function pointer.
--
user <candycane> is generated from /dev/urandom

Re: “ChattyG takes a college freshman C/C++ programming exam”

<20231008150352.5dfc8262244889e65a132733@gmail.moc>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2096&group=comp.lang.c%2B%2B#2096

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton.txt@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Date: Sun, 8 Oct 2023 15:03:52 +0300
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <20231008150352.5dfc8262244889e65a132733@gmail.moc>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<ufu3e1$2voq4$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="367339d4e143f1bde32c26e30c6cb416";
logging-data="3248079"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EuaFPqcK0XlWZw8NpLtu/Ej3aePcOJzA="
Cancel-Lock: sha1:UXiSZJbx2mPXeApkcJRS85pEimo=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sun, 8 Oct 2023 12:03 UTC

candycanearter07 to Anton Shepelev:

> > And although C allows the definition of self-referential
> > structs, it does [not] allow the declaration of self-
> > referencial functions.
>
> What if you typedef'd the function pointer?

That's what I did:

typedef void (*fp )( void );
typedef stm_fp (*func )( struct my_struct * s, int i );

As you see, the `func' still must return something other
than func...

> Also, you could probably get away with it by just setting
> it to a void pointer and casting the return value to the
> function pointer.

Yes, to a void /function/ pointer, because void* is
incompatible with void(*)(void). And then it is not a
truely recursive declaration, and requires additional work
to invoke. And the following does not compile, of course:

typedef func (*func )( struct my_struct * s, int i );

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: “ChattyG takes a college freshman C/C++ programming exam”

<87edi58eb2.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2099&group=comp.lang.c%2B%2B#2099

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Followup: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Followup-To: comp.lang.c
Date: Sun, 08 Oct 2023 13:54:41 +0100
Organization: A noiseless patient Spider
Lines: 89
Message-ID: <87edi58eb2.fsf@bsb.me.uk>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b80d8873568d9e06111403cd7c67c346";
logging-data="3270440"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19e3BGG6Gnc3Brfvrq9uyuWPDB5KfxECY8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:5Dyq3Ho/ym4BxjhqPjuNSkFD8yM=
sha1:Lgmp8irAPuhmCSv2vmIqQ3z9e1Q=
X-BSB-Auth: 1.581c6e214e16b521eb8f.20231008135441BST.87edi58eb2.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 8 Oct 2023 12:54 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:

> jak to Anton Shepelev:
>
>> > AS: Can a C function return a pointer to itself?
>> > CG: Yes, a C function can return a pointer to itself.
>>
>> The explanation is certainly wrong but it is true that it
>> is possible:
>
> I disagree. A function returns the value of its declared
> return type. And although C allows the definition of self-
> referential structs, it does [not] allow the declaration of self-
> referencial functions.

C does not have any way to express the /type/ of a function that returns
a pointer to itself. But self-referential functions (as most people
would use the term) are commonplace, many of them having very dull and
ordinary types!

>> #include <stdio.h>
>>
>> typedef void (* fptr)(int) ;
>>
>> fptr foo(int n)
>> {
>> printf("Call n. %d\n", n);
>> return (fptr)foo;
>> }
>>
>> int main()
>> {
>> fptr p = foo(1);
>> p(2);
>> return 0;
>> }

> You are converting void to function pointer fptr. This is not
> supported in C.

Not in the fragment shown. The conversion is from one
pointer-to-function type (void (*(*)(int))(int)) to another (void
(*)(int)) and that's allowed.

The trouble is that foo and foo(1) have different pointer-to-function
types. If C could express the right type, one could write

foo(1)(2)(3)(4);

but is it stands we can only write

foo(1)(2);

before the types go wrong. A third chained call would try to "call" a
void result.

> You might have taken advantage of
> void*, which is silently convertible to any pointer, but
> then again it does not work with function pointer, and C has
> not analog of void* for functions pointers, so an explicit
> conversion is seem inevitable.

I think it would be reasonable to say that a function /can/ return a
pointer to itself. It's just that the type will be wrong. After all,
we are happy to say that (void *)&some_int_var is a pointer to that int
object even though the type is wrong. To use that pointer to get at the
int object, a conversion is required. Similarly, to use the pointer
returned by a function like foo, a conversion is required. I would do
it like this:

#include <stdio.h>

typedef void (*generic_function_ptr)(void);
typedef generic_function_ptr (*fintp)(int);

generic_function_ptr foo(int n)
{
printf("Call n. %d\n", n);
return foo;
}

int main(void)
{
((fintp)((fintp)foo(1))(2))(3);
}

--
Ben.

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ufugkl$35c8r$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2100&group=comp.lang.c%2B%2B#2100

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c++
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Sun, 8 Oct 2023 11:08:05 -0400
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <ufugkl$35c8r$1@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 8 Oct 2023 15:08:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="895e1a872cd8d1da85552c30102c47a9";
logging-data="3322139"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19T/L3bClRbQJxpBOIUtCs1NBiLWs0RwXU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:7crKBlf1rhQqH4SJI5BSO2qpX7Y=
In-Reply-To: <uftmh9$2vieq$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Sun, 8 Oct 2023 15:08 UTC

On 10/8/23 03:42, jak wrote:
> Anton Shepelev ha scritto:
....
>> For me, it failed the very trivia:
>>
>> AS: Can a C function return a pointer to itself?
>>
>> CG: Yes, a C function can return a pointer to itself. This
>> is known as a recursive function, where a function calls
>> itself repeatedly until a certain condition is met. In
>> this case, the function would return a pointer to the
>> function itself to enable the recursive call.
>>
>> I asked that question here:
>>
>> <https://app.chatty-g.com/>
>>
>
> The explanation is certainly wrong but it is true that it is possible:
>
> #include <stdio.h>
>
> typedef void (* fptr)(int) ;
>
> fptr foo(int n)
> {
> printf("Call n. %d\n", n);
>
> return (fptr)foo;
> }
>
> int main()
> {
> fptr p = foo(1);
>
> p(2);

The return type of *p is void; the return type of foo is fptr.

Sorry - when I first wrote up a reply to this, I provided an answer that
cited the C standard. Then just before I posted it, I notices that I was
posting to comp.lang.c++, so I quickly "corrected" it to cite the C++
standard. And just now I noticed that the question was explicitly about
C. So here's the original citations:

"If the function is defined with a type that is not compatible with the
type (of the expression) pointed to by the expression that denotes the
called function, the behavior is undefined." (6.5.2.2p9).

"For two function types to be compatible, both shall specify compatible
return types." (6.7.5.3p15).

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ufuhm3$35c8r$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2101&group=comp.lang.c%2B%2B#2101

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c++
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Sun, 8 Oct 2023 11:25:55 -0400
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <ufuhm3$35c8r$2@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 8 Oct 2023 15:25:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="895e1a872cd8d1da85552c30102c47a9";
logging-data="3322139"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XheiUR9jkmbl4p5oUmjsL0EjrdTYBqEI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:E5iE79IZnBkl5kv0RS7b3IHdiQQ=
Content-Language: en-US
In-Reply-To: <20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
 by: James Kuyper - Sun, 8 Oct 2023 15:25 UTC

On 10/8/23 05:55, Anton Shepelev wrote:
> jak to Anton Shepelev:
>
>>> AS: Can a C function return a pointer to itself?
>>> CG: Yes, a C function can return a pointer to itself.
>>
>> The explanation is certainly wrong but it is true that it
>> is possible:
>
> I disagree. A function returns the value of its declared
> return type. And although C allows the definition of self-
> referential structs, it does allow the declaration of self-
> referencial functions.
>
>> #include <stdio.h>
>>
>> typedef void (* fptr)(int) ;
>>
>> fptr foo(int n)
>> {
>> printf("Call n. %d\n", n);
>> return (fptr)foo;

The line above converts "fptr(*)(int)" to "void(*)(int)'.

>> }
>>
>> int main()
>> {
>> fptr p = foo(1);>> p(2);
>> return 0;
>> }
>>
>> Out:
>>
>> Call n. 1
>> Call n. 2
>
> You are converting void to function pointer fptr. ...

I see no such conversion in the above code. Could you identify where it
occurs?

> ... This is
> not supported in C. You might have taken advantage of
> void*, which is silently convertible to any pointer, but
> then again it does not work with function pointer, and C has
> not analog of void* for functions pointers,so an explicit
> conversion is seem inevitable.

That's true - but the only conversion I can find in the above code is in
fact explicit, not implicit.
It's the function call that has undefined behavior, due to the code's
failure to convert the pointer back to it's original type. There's
nothing wrong with the conversion that is actually present.

Re: “ChattyG takes a college freshman C/C++ programming exam”

<pan$93d59$b5109882$fbf405c8$d4bea16f@invalid.invalid>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2102&group=comp.lang.c%2B%2B#2102

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemanedhawk@invalid.invalid (Blue-Maned_Hawk)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Date: Sun, 8 Oct 2023 16:37:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <pan$93d59$b5109882$fbf405c8$d4bea16f@invalid.invalid>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 8 Oct 2023 16:37:47 -0000 (UTC)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="fc98ecc332487388b7e4ecc06eaef4cd";
logging-data="3317311"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182sLMqOrb6d+R2upW+tBpPOZdxCKk5NJg="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:l08LzQyEY8Biib154mc8IoXySc4=
X-Face: Llanfair­pwllgwyng
yll
­gogeryÂÃ
? ?­chwyrnÂÂÂÂÂÂ
­drobwll­llanÃ
‚Ã
ƒƒƒ‚­tysilioÂÂÂÃ
‚­gogo­goch
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD
MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm
ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E
rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9
jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq
0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1
z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB
fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9
R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg
O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x
j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6
k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx
2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l
GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU
xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII=
 by: Blue-Maned_Hawk - Sun, 8 Oct 2023 16:37 UTC

Anton Shepelev wrote:

> You are converting void to function pointer fptr. This is not supported
> in C. You might have taken advantage of void*, which is silently
> convertible to any pointer, but then again it does not work with
> function pointer, and C has not analog of void* for functions pointers,
> so an explicit conversion is seem inevitable.

It mayn't be supported in standard C, but it's a common extension—in fact,
POSIX _requires_ it in order for the dlsym subroutine to work.

--
Blue-Maned_Hawk│shortens to
Hawk│/
blu.mɛin.dÊ°ak/
│he/him/his/himself/Mr.
bluemanedhawk.github.io
Y'know, the one with the thing!

Re: “ChattyG takes a college freshman C/C++ programming exam”

<20231008200536.2aebe46b71bae8b879b5bddb@gmail.moc>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2103&group=comp.lang.c%2B%2B#2103

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton.txt@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Date: Sun, 8 Oct 2023 20:05:36 +0300
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <20231008200536.2aebe46b71bae8b879b5bddb@gmail.moc>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<pan$93d59$b5109882$fbf405c8$d4bea16f@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="367339d4e143f1bde32c26e30c6cb416";
logging-data="3383384"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+pfbVsssbSik0KToBOTj6nLamXi90CyY="
Cancel-Lock: sha1:fkK7L3zt6QfTihWGaLL260r5O6Q=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sun, 8 Oct 2023 17:05 UTC

Blue-Maned_Hawk:
[Unicode em-dash replaced with --]
> [functions returning pointers to themselves]
> It mayn't be supported in standard C, but it's a common
> extension--in fact, POSIX _requires_ it in order for the
> dlsym subroutine to work.

How so, when casing the return value (from a different
function pointer) does not solve the problem?

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: “ChattyG takes a college freshman C/C++ programming exam”

<20231008200739.218fcb4a86747e3858f579ec@gmail.moc>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2104&group=comp.lang.c%2B%2B#2104

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton.txt@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c++
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Date: Sun, 8 Oct 2023 20:07:39 +0300
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <20231008200739.218fcb4a86747e3858f579ec@gmail.moc>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<ufuhm3$35c8r$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="367339d4e143f1bde32c26e30c6cb416";
logging-data="3383384"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Jvax6xU+fSV9CRORdlrwrbM7NYkHlE2M="
Cancel-Lock: sha1:uQOya/KmEKHnqEmgBlY2hT+NrRI=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sun, 8 Oct 2023 17:07 UTC

James Kuyper to Anton Shepelev:

> > You are converting void to function pointer fptr. ...
>
> I see no such conversion in the above code. Could you
> identify where it occurs?

You are correct. I overlooked that the OP's ignores the
return value, and therefore need not convert it to anything
to make it useful.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ufv02a$398hi$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2107&group=comp.lang.c%2B%2B#2107

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Sun, 8 Oct 2023 12:31:21 -0700
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <ufv02a$398hi$1@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<ufu3e1$2voq4$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 8 Oct 2023 19:31:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ebca3b7c70a663ebe6c771f7b2cfc517";
logging-data="3449394"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Nx/Y4+4qGF9aaeRsm/OF4xMy9dHmG5Lc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:JUh5R8ByMvdKS/RjU8WAf3qZ1DI=
In-Reply-To: <ufu3e1$2voq4$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sun, 8 Oct 2023 19:31 UTC

On 10/8/2023 4:22 AM, candycanearter07 wrote:
> On 10/8/23 04:55, Anton Shepelev wrote:
>> I disagree.  A function returns the value of its declared
>> return type.  And although C allows the definition of self-
>> referential structs, it does allow the declaration of self-
>> referencial functions.
>
> What if you typedef'd the function pointer?
>
> Also, you could probably get away with it by just setting it to a void
> pointer and casting the return value to the function pointer.

Not sure if that's allowed. A function pointer cast to a void pointer,
which in turn is cast back to a function pointer is undefined? What am I
forgetting here?

Re: “ChattyG takes a college freshman C/C++ programming exam”

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

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2110&group=comp.lang.c%2B%2B#2110

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Date: Sun, 08 Oct 2023 15:31:37 -0700
Organization: None to speak of
Lines: 26
Message-ID: <87cyxovj92.fsf@nosuchdomain.example.com>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<pan$93d59$b5109882$fbf405c8$d4bea16f@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="36b234a63abc118e06965f15a687a623";
logging-data="3528715"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CAGn4ME8O6tkdS3v7jCF+"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:q7yXlx2RSAkdxexH4CS5w5v80Ik=
sha1:Q3nBrT8dSrtR1nN8QjZubI+NupQ=
 by: Keith Thompson - Sun, 8 Oct 2023 22:31 UTC

Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> writes:
> Anton Shepelev wrote:
>> You are converting void to function pointer fptr. This is not supported
>> in C. You might have taken advantage of void*, which is silently
>> convertible to any pointer, but then again it does not work with
>> function pointer, and C has not analog of void* for functions pointers,
>> so an explicit conversion is seem inevitable.
>
> It mayn't be supported in standard C, but it's a common extension—in fact,
> POSIX _requires_ it in order for the dlsym subroutine to work.

The POSIX requirement is limited to values returned by dlsym().

https://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html

> The return value from dlsym(), cast to a pointer to the type of the
> named symbol, can be used to call (in the case of a function) or access
> the contents of (in the case of a data object) the named symbol.

An implementation could satisfy that requirement without supporting
void* to function pointer conversions in general.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ufvkar$3e7t0$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2111&group=comp.lang.c%2B%2B#2111

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: news.x.richarddamon@xoxy.net (Richard Damon)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Sun, 8 Oct 2023 21:17:15 -0400
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <ufvkar$3e7t0$1@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<ufu3e1$2voq4$2@dont-email.me> <ufv02a$398hi$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 9 Oct 2023 01:17:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="977b00f5a78722ed66f532c2ab3e9b30";
logging-data="3612576"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ZcY2IBTESsltSM+ADvW1VCA+XA9TfBYU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:cmHtwXeZH5wvi7aEDVCbla53hxw=
In-Reply-To: <ufv02a$398hi$1@dont-email.me>
Content-Language: en-US
 by: Richard Damon - Mon, 9 Oct 2023 01:17 UTC

On 10/8/23 3:31 PM, Chris M. Thomasson wrote:
> On 10/8/2023 4:22 AM, candycanearter07 wrote:
>> On 10/8/23 04:55, Anton Shepelev wrote:
>>> I disagree.  A function returns the value of its declared
>>> return type.  And although C allows the definition of self-
>>> referential structs, it does allow the declaration of self-
>>> referencial functions.
>>
>> What if you typedef'd the function pointer?
>>
>> Also, you could probably get away with it by just setting it to a void
>> pointer and casting the return value to the function pointer.
>
> Not sure if that's allowed. A function pointer cast to a void pointer,
> which in turn is cast back to a function pointer is undefined? What am I
> forgetting here?

While not specifically called out as undefined behavior, it also isn't
ever said to be allowed.

It will work on the most common processors currently, but I have an
active product using a processor where it will definitely NOT work, as
function pointers are bigger than object pointers.

The Posix standard sort of requires that it works, but only for a
certain set of function pointers, so you can do a work around for
machines that don't actually support it.

One way to acheive the results is define the return type as a pointer to
some defined type of function, and you cast the return value to a
pointer to a function that returns that type of function, and in the
function cast the pointer to itself to that type of function.

i.e.

typedef void (*fret)(); // fret is a simplifed type we can return
typedef fret (*pf)(); // pf is the actual type of the function.

fret func() {
return (fret) func;
}

int main() {

pf p = (pf)func(); // Call the function and cast the return value
pf p2 = (pf)p(); // call the same function from the pointer
}

Note, the standard specifically says we can cast any function pointer
type to another function pointer type and back and get a usable pointer.

(untested code, but should be at least close)

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ug0230$3lhhc$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2112&group=comp.lang.c%2B%2B#2112

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c++
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Mon, 9 Oct 2023 01:12:00 -0400
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <ug0230$3lhhc$1@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<pan$93d59$b5109882$fbf405c8$d4bea16f@invalid.invalid>
<87cyxovj92.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 9 Oct 2023 05:12:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a5ee3b6b247e32fb22817897dba89fee";
logging-data="3851820"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+O05kJJN/am+yrIA2JDG6AsqpKMPjYCCw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tBlyWfCznO52wn+CwARXihxOhvA=
In-Reply-To: <87cyxovj92.fsf@nosuchdomain.example.com>
Content-Language: en-US
 by: James Kuyper - Mon, 9 Oct 2023 05:12 UTC

On 10/8/23 18:31, Keith Thompson wrote:
> Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> writes:
>> Anton Shepelev wrote:
>>> You are converting void to function pointer fptr. This is not supported
>>> in C. You might have taken advantage of void*, which is silently
>>> convertible to any pointer, but then again it does not work with
>>> function pointer, and C has not analog of void* for functions pointers,
>>> so an explicit conversion is seem inevitable.
>>
>> It mayn't be supported in standard C, but it's a common extension—in fact,
>> POSIX _requires_ it in order for the dlsym subroutine to work.
>
> The POSIX requirement is limited to values returned by dlsym().
>
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html

I've heard that before, and it might be true - but I don't see words to
that effect on that page. It says:

"Note that conversion from a void * pointer to a function pointer as in:

fptr = (int (*)(int))dlsym(handle, "my_function");

is not defined by the ISO C standard. This standard requires this
conversion to work correctly on conforming implementations."

As I read it, that requires that the conversion work in general - it
says nothing about it working only for values returned by dlsym.

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ug0251$3lhhc$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2113&group=comp.lang.c%2B%2B#2113

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c++
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Mon, 9 Oct 2023 01:13:05 -0400
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <ug0251$3lhhc$2@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<ufu3e1$2voq4$2@dont-email.me> <ufv02a$398hi$1@dont-email.me>
<ufvkar$3e7t0$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 9 Oct 2023 05:13:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a5ee3b6b247e32fb22817897dba89fee";
logging-data="3851820"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yh2uZbj531WTTX8HFdDMs8eWQ8EpD0EU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:stDzJHWX2lMyVVPTQ+YtDZtX8V8=
In-Reply-To: <ufvkar$3e7t0$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Mon, 9 Oct 2023 05:13 UTC

On 10/8/23 21:17, Richard Damon wrote:
> On 10/8/23 3:31 PM, Chris M. Thomasson wrote:
....
>> Not sure if that's allowed. A function pointer cast to a void
>> pointer, which in turn is cast back to a function pointer is
>> undefined? What am I forgetting here?
>
> While not specifically called out as undefined behavior, it also isn't
> ever said to be allowed.

Precisely - it is undefined "... by the omission of any explicit
definition of behavior." (4p2

Re: “ChattyG takes a college freshman C/C++ programming exam”

<ug0267$3lhhc$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2114&group=comp.lang.c%2B%2B#2114

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c++
Subject: Re:_“ChattyG_takes_a_college_freshman_C/C++_pro
gramming_exam”
Date: Mon, 9 Oct 2023 01:13:43 -0400
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <ug0267$3lhhc$3@dont-email.me>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<pan$93d59$b5109882$fbf405c8$d4bea16f@invalid.invalid>
<20231008200536.2aebe46b71bae8b879b5bddb@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 9 Oct 2023 05:13:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a5ee3b6b247e32fb22817897dba89fee";
logging-data="3851820"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188mKRsbtC24CpvAF0/i/hOB/y/sqwEzdY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:sUI+fTG11IuGj1VBm/sf9Y+aQog=
Content-Language: en-US
In-Reply-To: <20231008200536.2aebe46b71bae8b879b5bddb@gmail.moc>
 by: James Kuyper - Mon, 9 Oct 2023 05:13 UTC

On 10/8/23 13:05, Anton Shepelev wrote:
> Blue-Maned_Hawk:
> [Unicode em-dash replaced with --]
>> [functions returning pointers to themselves]
>> It mayn't be supported in standard C, but it's a common
>> extension--in fact, POSIX _requires_ it in order for the
>> dlsym subroutine to work.
>
> How so, when casing the return value (from a different
> function pointer) does not solve the problem?

The problem is behavior that is not defined by the C standard. POSIX
solves the problem by defining the behavior:

"Note that conversion from a void * pointer to a function pointer as in:

fptr = (int (*)(int))dlsym(handle, "my_function");

is not defined by the ISO C standard. This standard requires this
conversion to work correctly on conforming implementations."

"This standard" refers to the POSIX standard, not the C standard.

Re: “ChattyG takes a college freshman C/C++ programming exam”

<pan$da5cd$33b40da2$e72bf6b3$e30efcdc@invalid.invalid>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2115&group=comp.lang.c%2B%2B#2115

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemanedhawk@invalid.invalid (Blue-Maned_Hawk)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Date: Mon, 9 Oct 2023 12:17:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <pan$da5cd$33b40da2$e72bf6b3$e30efcdc@invalid.invalid>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<pan$93d59$b5109882$fbf405c8$d4bea16f@invalid.invalid>
<20231008200536.2aebe46b71bae8b879b5bddb@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 9 Oct 2023 12:17:23 -0000 (UTC)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="aa0f0d6a46ea3d1355477450eb514c69";
logging-data="4070488"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lJPSVN7DY3PDS4WMLessMzSxlyEy7t5A="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:zBj9vPdbdeHqSkdLA/rcB7Rztv4=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD
MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm
ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E
rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9
jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq
0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1
z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB
fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9
R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg
O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x
j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6
k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx
2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l
GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU
xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII=
X-Face: Llanfair­pwllgwyng
yll
­gogeryÂÃ
? ?­chwyrnÂÂÂÂÂÂ
­drobwll­llanÃ
‚Ã
ƒƒƒ‚­tysilioÂÂÂÃ
‚­gogo­goch
 by: Blue-Maned_Hawk - Mon, 9 Oct 2023 12:17 UTC

Anton Shepelev wrote:

> Blue-Maned_Hawk:
> [Unicode em-dash replaced with --]

Why?

>> [functions returning pointers to themselves]
>> It mayn't be supported in standard C, but it's a common extension--in
>> fact, POSIX _requires_ it in order for the dlsym subroutine to work.
>
> How so, when casing the return value (from a different function pointer)
> does not solve the problem?

I was not referring to functions returning pointers to themselves in the
quoted part of my message. I was referring to void * being castable to a
function pointer.

--
Blue-Maned_Hawk│shortens to
Hawk│/
blu.mɛin.dÊ°ak/
│he/him/his/himself/Mr.
bluemanedhawk.github.io
Variably constant!

Re: “ChattyG takes a college freshman C/C++ programming exam”

<20231009230305.adfd0d80c146dc966ab22443@gmail.moc>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2116&group=comp.lang.c%2B%2B#2116

  copy link   Newsgroups: comp.lang.c++ comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton.txt@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: “ChattyG takes a college freshman C/C++
programming exam”
Date: Mon, 9 Oct 2023 23:03:05 +0300
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <20231009230305.adfd0d80c146dc966ab22443@gmail.moc>
References: <ufne0r$15ple$1@dont-email.me>
<20231007235448.25c4986f123c88ff65d2f103@gmail.moc>
<uftmh9$2vieq$1@dont-email.me>
<20231008125543.518cab44cdefed7e8af393c8@gmail.moc>
<pan$93d59$b5109882$fbf405c8$d4bea16f@invalid.invalid>
<20231008200536.2aebe46b71bae8b879b5bddb@gmail.moc>
<pan$da5cd$33b40da2$e72bf6b3$e30efcdc@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="404cc1cc3d5d5d1907a85a6573344343";
logging-data="119227"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MAdOT5Xqqkjv3dJtGyqayoFpWQmbzLM4="
Cancel-Lock: sha1:n/iuEewM1Hqtv3zuam+KTJY/iNM=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Mon, 9 Oct 2023 20:03 UTC

Blue-Maned_Hawk to Anton Shepelev:

> > Blue-Maned_Hawk:
> > [Unicode em-dash replaced with --]
>
> Why?

Oh, it just doesn't go with Usenet, stylistically and
aesthetically. English plain-text is must like
code -- 7-bit-clean. And like code (e.g. for Troff or
LaTeX), there are convensions for dashes, /italic/ text,
<URLs>, &c. Your signature is a mess of Unicode
characters -- terrible :-!

> > > It mayn't be supported in standard C, but it's a
> > > common extension--in fact, POSIX _requires_ it in
> > > order for the dlsym subroutine to work.
> >
> > How so, when casing the return value (from a different
> > function pointer) does not solve the problem?
>
> I was not referring to functions returning pointers to
> themselves in the quoted part of my message. I was
> referring to void * being castable to a function pointer.

Yes, and I asked why the authors of that API decided not to
use the casing that is guarranteed to work, preferring the
dubious casing of void* to function pointers. If /I/ were
the designer (should you be afraid?), I should make it two
functions:

void * dlsym_o(void *restrict handle, const char *restrict name);
void(*)(void) dlsym_f(void *restrict handle, const char *restrict name);

because the caller usually knows what he seeks. If he
doesn't, let it be a single function with a compund return
type. I am not sure what a good way to do it would be,
however, because, having to declare a struct, (with possibly
an union inside) and an enum just for this function may be
bloat, yet:--

enum dlsym_type {dsOBJ, dsFUN, dsNA}; /* the 3rd member optional */

struct dlsym_info
{ char is_found; /* flag, optional */
enum dlsym_type type ; /* optional */
void * obj_ptr ; /* NULL if not found */
void(*)(void) fun_ptr ; /* NULL if not found */
}

`optional' above means the element may be omitted from the
interface. For example, dsNA and .is_found are mutually
exclusive, and both the flag and the enum may be done away
with by requiring that the caller use whichever pointer is
not NULL, and consider the symbol not found if both are
NULL.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Pages:123
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor