Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

A fail-safe circuit will destroy others. -- Klipstein


devel / comp.lang.c / Call to a function

SubjectAuthor
* Call to a functionStefan Ram
+* Re: Call to a functionKaz Kylheku
|+* Re: Call to a functionJames Kuyper
||`* Re: Call to a functionKaz Kylheku
|| +- Re: Call to a functionJames Kuyper
|| `- Re: Call to a functionTim Rentsch
|`* Re: Call to a functionKeith Thompson
| `* Re: Call to a functionTim Rentsch
|  `* Re: Call to a functionKeith Thompson
|   +* Re: Call to a functionKaz Kylheku
|   |`- Re: Call to a functionKeith Thompson
|   +- Re: Call to a functionChris M. Thomasson
|   `* Re: Call to a functionTim Rentsch
|    +* Re: Call to a functionRichard Damon
|    |`- Re: Call to a functionTim Rentsch
|    +* Re: Call to a functionKeith Thompson
|    |`* Re: Call to a functionTim Rentsch
|    | +* Re: Call to a functionKaz Kylheku
|    | |`- Re: Call to a functionTim Rentsch
|    | `* Re: Call to a functionPhil Carmody
|    |  +- Re: Call to a functionKeith Thompson
|    |  `* Re: Call to a functionTim Rentsch
|    |   `* Re: Call to a functionPhil Carmody
|    |    `* Re: Call to a functionTim Rentsch
|    |     `* Re: Call to a functionPhil Carmody
|    |      +- Re: Call to a functionJames Kuyper
|    |      `- Re: Call to a functionTim Rentsch
|    +* Re: Call to a functionJames Kuyper
|    |+* Re: Call to a functionKaz Kylheku
|    ||`* Re: Call to a functionJames Kuyper
|    || `* Re: Call to a functionKeith Thompson
|    ||  +* Re: Call to a functionKaz Kylheku
|    ||  |`- Re: Call to a functionKeith Thompson
|    ||  `* Re: Call to a functionJames Kuyper
|    ||   +* Re: Call to a functionKeith Thompson
|    ||   |+* Re: Call to a functionJames Kuyper
|    ||   ||`- OT: Retirement (was Re: Call to a function)Vir Campestris
|    ||   |`- Re: Call to a functionTim Rentsch
|    ||   `* Re: Call to a functionKenny McCormack
|    ||    +- Re: Call to a functionKaz Kylheku
|    ||    `- Re: Call to a functionJames Kuyper
|    |+* Re: Call to a functionTim Rentsch
|    ||`* Re: Call to a functionKeith Thompson
|    || +- Re: Call to a functionTim Rentsch
|    || +- Re: Call to a functionTim Rentsch
|    || +* Re: Call to a functionTim Rentsch
|    || |`* Re: Call to a functionKeith Thompson
|    || | `* Re: Call to a functionTim Rentsch
|    || |  `* Re: Call to a functionLawrence D'Oliveiro
|    || |   +- Re: Call to a functionKeith Thompson
|    || |   `* Re: Call to a functionScott Lurndal
|    || |    `- Re: Call to a functionLawrence D'Oliveiro
|    || `* Re: Call to a functionJames Kuyper
|    ||  +- Re: Call to a functionTim Rentsch
|    ||  `- Re: Call to a functionJames Kuyper
|    |+* Re: Call to a functionJames Kuyper
|    ||`- Re: Call to a functionTim Rentsch
|    |`* Re: Call to a functionJames Kuyper
|    | +- Re: Call to a functionTim Rentsch
|    | `* Re: Call to a functionJames Kuyper
|    |  +- Re: Call to a functionTim Rentsch
|    |  +* Re: Call to a functionJames Kuyper
|    |  |`- Re: Call to a functionTim Rentsch
|    |  `* Re: Call to a functionJames Kuyper
|    |   +- Re: Call to a functionKeith Thompson
|    |   `- Re: Call to a functionTim Rentsch
|    `- Re: Call to a functionKaz Kylheku
`* Re: Call to a functionTim Rentsch
 `* Re: Call to a functionBen Bacarisse
  `* Re: Call to a functionTim Rentsch
   `* Re: Call to a functionBen Bacarisse
    +* Re: Call to a functionVir Campestris
    |`* Re: Call to a functionBen Bacarisse
    | `* Re: Call to a functionVir Campestris
    |  `* Re: Call to a functionBen Bacarisse
    |   `- OT: ICL PERQ (was Re: Call to a function)Vir Campestris
    `- Re: Call to a functionTim Rentsch

Pages:1234
Call to a function

<call-20230922130647@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Call to a function
Date: 22 Sep 2023 12:24:28 GMT
Organization: Stefan Ram
Lines: 20
Expires: 1 Sep 2024 11:59:58 GMT
Message-ID: <call-20230922130647@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de HkA8c+nvp4THeUlaye7X+gI7UgXMjl9q835ltTYP00v2em
Cancel-Lock: sha1:HqcJE93EkwAW03WLoElC5zJ3B18= sha256:LNVLk5MUhaMeiCGN+Mngu4qb51rwquMnFXsVvffcPiA=
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Fri, 22 Sep 2023 12:24 UTC

When "1" is cast to a function type and then this is called,
one would expect this call to have undefined behavior. But
I can only find this in the C specification:

|If a converted pointer is used to call a function whose type
|is not compatible with the referenced type, the behavior is
|undefined.

. At the address "1" there is not "a function whose type is not
compatible", but no function at all. Is "no function at all" also
"a function whose type is not compatible with the referenced type"
or is there some other part of the specification by which a call
to an address where there is no function at all has UB?

Then, when "f()" is being evaluated and there is no UB, I'd
expect the control to temporarily be transfered to f. The C
spec has a section "Function Calls" under "Postfix Operators",
but I cannot find anything there that actually says this.

Re: Call to a function

<20230922081706.858@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Fri, 22 Sep 2023 15:21:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <20230922081706.858@kylheku.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
Injection-Date: Fri, 22 Sep 2023 15:21:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="178c3857704d977ee6ffe0460286225b";
logging-data="332195"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3WWnJJ9o+8OoWOmCdOX3XHZ3hmmenVzc="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:oafyR4lDUHvmJSFaJBojf3U/XNw=
 by: Kaz Kylheku - Fri, 22 Sep 2023 15:21 UTC

On 2023-09-22, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> When "1" is cast to a function type and then this is called,
> one would expect this call to have undefined behavior. But
> I can only find this in the C specification:
>
>|If a converted pointer is used to call a function whose type
>|is not compatible with the referenced type, the behavior is
>|undefined.

Because ISO C supports conversions between function pointer types,
above, the document is addressing what happens in the situation
when the address of a function is converted to a different pointer type,
which is then called. E.g. int puts(const char *) is misused as
a void (double) function:

void (*fptr)(double) = (void (*)(double)) puts;

So far, the behavior is defined: the conversion is valid.
The pointer could be converted to the correct type and used:

So, the above remarks make it clear that

fptr(3.14);

isn't defined.

> . At the address "1" there is not "a function whose type is not
> compatible", but no function at all.

The conversion is not supported by ISO C, and so itself has
undefined behavior:

void (*fptr)(double) = (void (*)(double)) 1;

There is no need to make remarks about the consequences of
using a pointer which was obtained by undefined behavior.

--
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: Call to a function

<uekcfs$a1at$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Fri, 22 Sep 2023 11:39:40 -0400
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <uekcfs$a1at$1@dont-email.me>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<20230922081706.858@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 15:39:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bc676d1a2055933b817fd3312fab2ca3";
logging-data="329053"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VK2KjN07mR+GEpk1N6Sz+t3rB54lGi9I="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:B2cVzRiHTc1wNinLV6Ft/NIYHDc=
In-Reply-To: <20230922081706.858@kylheku.com>
Content-Language: en-US
 by: James Kuyper - Fri, 22 Sep 2023 15:39 UTC

On 9/22/23 11:21, Kaz Kylheku wrote:
> On 2023-09-22, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>> When "1" is cast to a function type and then this is called,
>> one would expect this call to have undefined behavior. But
>> I can only find this in the C specification:
>>
>> |If a converted pointer is used to call a function whose type
>> |is not compatible with the referenced type, the behavior is
>> |undefined.
>
> Because ISO C supports conversions between function pointer types,
> above, the document is addressing what happens in the situation
> when the address of a function is converted to a different pointer type,
> which is then called. E.g. int puts(const char *) is misused as
> a void (double) function:
>
> void (*fptr)(double) = (void (*)(double)) puts;
>
> So far, the behavior is defined: the conversion is valid.
> The pointer could be converted to the correct type and used:
>
> So, the above remarks make it clear that
>
> fptr(3.14);
>
> isn't defined.
>
>> . At the address "1" there is not "a function whose type is not
>> compatible", but no function at all.
>
> The conversion is not supported by ISO C, and so itself has
> undefined behavior:
>
> void (*fptr)(double) = (void (*)(double)) 1;
"An integer may be converted to any pointer type. Except as previously
specified, the result is implementation-defined, might not be correctly
aligned, might not point to an entity of the referenced type, and might
be a trap representation." (6.3.2.3p5).

The conversion itself is supported, it's just not guaranteed to result
in a pointer to "an entity of the referenced type". I would expect that
calling a function through a pointer that does not point at a function
would result in undefined behavior - but I think Stefan has a point -
I'm having trouble locating the part of the standard that explicitly
says so. I suppose that such a pointer could be considered to be a trap
representation. But even so, it's what you do with the resulting pointer
value that has undefined behavior, not the conversion itself.

Re: Call to a function

<20230922091405.491@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Fri, 22 Sep 2023 16:47:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <20230922091405.491@kylheku.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<20230922081706.858@kylheku.com> <uekcfs$a1at$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Sep 2023 16:47:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="178c3857704d977ee6ffe0460286225b";
logging-data="361849"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18uy+OHVIuWTdwGY2BS/MvqOjsJMpher3Q="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:eN0WptFpjnLB714+6R6cvlAYFNQ=
 by: Kaz Kylheku - Fri, 22 Sep 2023 16:47 UTC

On 2023-09-22, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
> On 9/22/23 11:21, Kaz Kylheku wrote:
>> The conversion is not supported by ISO C, and so itself has
>> undefined behavior:
>>
>> void (*fptr)(double) = (void (*)(double)) 1;
> "An integer may be converted to any pointer type. Except as previously
> specified, the result is implementation-defined, might not be correctly
> aligned, might not point to an entity of the referenced type, and might
> be a trap representation." (6.3.2.3p5).
>
> The conversion itself is supported, it's just not guaranteed to result
> in a pointer to "an entity of the referenced type". I would expect that
> calling a function through a pointer that does not point at a function
> would result in undefined behavior - but I think Stefan has a point -
> I'm having trouble locating the part of the standard that explicitly
> says so. I suppose that such a pointer could be considered to be a trap
> representation. But even so, it's what you do with the resulting pointer
> value that has undefined behavior, not the conversion itself.

Thanks for the correction.

You would think that the description of function call expressions covers
this. E.g. in C99 we had the wording:

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.

Whatever is at the address arising from the conversion of 1, if that is
an address, it is not a function defined with a type pointed to by the
pointer expression.

Also, this is tangentially relevant from Address and indirection
operators:

The unary * operator denotes indirection. If the operand points to a
function, the result is a function designator; if it points to an
object, the result is an lvalue designating the object. If the operand
has type ‘‘pointer to type’’, the result has type ‘‘type’’. If an
invalid value has been assigned to the pointer, the behavior of the
unary * operator is undefined.

An invalid function pointer cannot be deferenced using * in order
to designate a function. So that rules out (*f)() from being
well-defined, which casts doubt on f().

--
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: Call to a function

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Fri, 22 Sep 2023 11:54:24 -0700
Organization: None to speak of
Lines: 46
Message-ID: <87zg1et4wv.fsf@nosuchdomain.example.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<20230922081706.858@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b6cf63bcc3bc7ea5218df73d2693f74f";
logging-data="403474"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18w7SPJr/ybrHwsgMeGEhKk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:+V5F8iVnIJU6XXafk1Tbp1SSF2Y=
sha1:PJ7/P+plTkDVmcrakLHH4p61peI=
 by: Keith Thompson - Fri, 22 Sep 2023 18:54 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:
> On 2023-09-22, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>> When "1" is cast to a function type and then this is called,
>> one would expect this call to have undefined behavior. But
>> I can only find this in the C specification:
>>
>>|If a converted pointer is used to call a function whose type
>>|is not compatible with the referenced type, the behavior is
>>|undefined.
>
> Because ISO C supports conversions between function pointer types,
> above, the document is addressing what happens in the situation
> when the address of a function is converted to a different pointer type,
> which is then called. E.g. int puts(const char *) is misused as
> a void (double) function:
>
> void (*fptr)(double) = (void (*)(double)) puts;
>
> So far, the behavior is defined: the conversion is valid.
> The pointer could be converted to the correct type and used:
>
> So, the above remarks make it clear that
>
> fptr(3.14);
>
> isn't defined.
>
>> . At the address "1" there is not "a function whose type is not
>> compatible", but no function at all.
>
> The conversion is not supported by ISO C, and so itself has
> undefined behavior:
>
> void (*fptr)(double) = (void (*)(double)) 1;

The original post used "1", a string literal. You assumed it was an
integer constant in quotes. The point is the same either way, but
Stefan, it might have been clearer if you had shown sample code.

> There is no need to make remarks about the consequences of
> using a pointer which was obtained by undefined behavior.

--
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: Call to a function

<uelsth$lofc$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Sat, 23 Sep 2023 01:26:09 -0400
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <uelsth$lofc$1@dont-email.me>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<20230922081706.858@kylheku.com> <uekcfs$a1at$1@dont-email.me>
<20230922091405.491@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 05:26:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cb455f970ba1687f5f3b6aedfb346eeb";
logging-data="713196"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lwxXrerLL7zF/xp6ne8ZpEIvQ/12w+Gc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:9Dw8jshM3sDJdUfjI89mPWnxO6w=
In-Reply-To: <20230922091405.491@kylheku.com>
Content-Language: en-US
 by: James Kuyper - Sat, 23 Sep 2023 05:26 UTC

On 9/22/23 12:47, Kaz Kylheku wrote:
> On 2023-09-22, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>> On 9/22/23 11:21, Kaz Kylheku wrote:
>>> The conversion is not supported by ISO C, and so itself has
>>> undefined behavior:
>>>
>>> void (*fptr)(double) = (void (*)(double)) 1;
>> "An integer may be converted to any pointer type. Except as previously
>> specified, the result is implementation-defined, might not be correctly
>> aligned, might not point to an entity of the referenced type, and might
>> be a trap representation." (6.3.2.3p5).
>>
>> The conversion itself is supported, it's just not guaranteed to result
>> in a pointer to "an entity of the referenced type". I would expect that
>> calling a function through a pointer that does not point at a function
>> would result in undefined behavior - but I think Stefan has a point -
>> I'm having trouble locating the part of the standard that explicitly
>> says so. I suppose that such a pointer could be considered to be a trap
>> representation. But even so, it's what you do with the resulting pointer
>> value that has undefined behavior, not the conversion itself.
>
> Thanks for the correction.
>
> You would think that the description of function call expressions covers
> this. E.g. in C99 we had the wording:
>
> 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.

That's 6.5.2.2p9 in the latest version of the standard that I have
access to.

> Whatever is at the address arising from the conversion of 1, if that is
> an address, it is not a function defined with a type pointed to by the
> pointer expression.

Correct. What the pointer points at is NOT a function, and is therefore,
in particular, not a function "defined with a type that is not
compatible ...". Therefore, 6.5.2.2p9 doesn't apply, and is therefore
not the reasons the behavior is undefined.

I've come to the conclusion that it's undefined by the omission of any
applicable explicit definition of the behavior (4p2).

Re: Call to a function

<86v8c1j6op.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Sat, 23 Sep 2023 07:38:30 -0700
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <86v8c1j6op.fsf@linuxsc.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de> <20230922081706.858@kylheku.com> <uekcfs$a1at$1@dont-email.me> <20230922091405.491@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="bbbdca6269fb3628276797e440c29686";
logging-data="884295"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1++u7frHu6a7gekbVZnyyufOkv09NE/mIY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:cBF2eBn5XLmQh/jOl4+i3+MZwiU=
sha1:xzAlKHLRdPGLC6AeXJ7im/5Ec/4=
 by: Tim Rentsch - Sat, 23 Sep 2023 14:38 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:

> On 2023-09-22, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>
>> On 9/22/23 11:21, Kaz Kylheku wrote:
>>
>>> The conversion is not supported by ISO C, and so itself has
>>> undefined behavior:
>>>
>>> void (*fptr)(double) = (void (*)(double)) 1;
>>
>> "An integer may be converted to any pointer type. Except as previously
>> specified, the result is implementation-defined, might not be correctly
>> aligned, might not point to an entity of the referenced type, and might
>> be a trap representation." (6.3.2.3p5).
>>
>> The conversion itself is supported, it's just not guaranteed to result
>> in a pointer to "an entity of the referenced type". I would expect that
>> calling a function through a pointer that does not point at a function
>> would result in undefined behavior - but I think Stefan has a point -
>> I'm having trouble locating the part of the standard that explicitly
>> says so. I suppose that such a pointer could be considered to be a trap
>> representation. But even so, it's what you do with the resulting pointer
>> value that has undefined behavior, not the conversion itself.
>
> Thanks for the correction.
>
> You would think that the description of function call expressions covers
> this. E.g. in C99 we had the wording:
>
> 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.
>
> Whatever is at the address arising from the conversion of 1, if that is
> an address, it is not a function defined with a type pointed to by the
> pointer expression.

It _could_ be a function. The mapping from integers to pointers
is implementation defined. There is no reason an implementation
couldn't define the conversion of integers to function pointers
as the nth function in the overall program, with functions being
listed alphabetically. So if a program defines a function

void aardvark( double d ){ (void)&d; }

then that program, with this definition of main(),

int main( void ){
((void (*)( double )) 1) ( 3.14 );
return 0;
}

could be a well-defined (as well as well-formed) program for that
implementation.

Re: Call to a function

<86r0mokgu8.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Sat, 23 Sep 2023 09:13:51 -0700
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <86r0mokgu8.fsf@linuxsc.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="bbbdca6269fb3628276797e440c29686";
logging-data="916425"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/HG0Hfa80WUCSq2ZlNLgCC40cv496gIEI="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:U9Vs2irGLJD+h1wC50YqZZIjpyI=
sha1:KtKZMZSAqE94lzqRNjg53xLUM/M=
 by: Tim Rentsch - Sat, 23 Sep 2023 16:13 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> When "1" is cast to a function type and then this is called,
> one would expect this call to have undefined behavior. But
> I can only find this in the C specification:

Of course what you mean is there is a cast to a pointer to
function type. The C standard requires the casted-to type
to be a scalar type, and functions are not scalar types,
so a pointer-to-function type is needed.

> |If a converted pointer is used to call a function whose type
> |is not compatible with the referenced type, the behavior is
> |undefined.
>
> . At the address "1" there is not "a function whose type is not
> compatible", but no function at all.

An implementation could choose to convert an integer 1 to
a pointer to an actual function, because the mapping is
implementation defined. Of course it's very likely that it
won't be, but it could be.

> Is "no function at all" also
> "a function whose type is not compatible with the referenced type"
> or is there some other part of the specification by which a call
> to an address where there is no function at all has UB?

As James Kuyper rightly points out, trying to call through a
pointer that doesn't point to an actual function is undefined
behavior by virtue of the C standard not defining what happens
in such cases. Not having a definition has exactly the same
consequences as the standard giving an explicit statement that
the behavior is undefined (because the C standard says so).

Re: Call to a function

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Sat, 23 Sep 2023 22:54:15 +0100
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <87wmwgh7y0.fsf@bsb.me.uk>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<86r0mokgu8.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="55b414175deac24d53d7dcd307fb4e06";
logging-data="1039639"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jEp35wJl5siHu41IQqX9Wg9LjMmgJALc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:Cz5zF9QfDn3cY3Koqk9F32ZJuQY=
sha1:FEqTLsVFDCHySDN2opzFmQbphkw=
X-BSB-Auth: 1.eb2d9072cf00ec577727.20230923225415BST.87wmwgh7y0.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 23 Sep 2023 21:54 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>
>> When "1" is cast to a function type and then this is called,
>> one would expect this call to have undefined behavior. But
>> I can only find this in the C specification:
>
> Of course what you mean is there is a cast to a pointer to
> function type. The C standard requires the casted-to type
> to be a scalar type, and functions are not scalar types,
> so a pointer-to-function type is needed.
>
>> |If a converted pointer is used to call a function whose type
>> |is not compatible with the referenced type, the behavior is
>> |undefined.
>>
>> . At the address "1" there is not "a function whose type is not
>> compatible", but no function at all.
>
> An implementation could choose to convert an integer 1 to
> a pointer to an actual function, because the mapping is
> implementation defined. Of course it's very likely that it
> won't be, but it could be.

I worked on a C compiler that did just this. The machine put every
function into it's own memory segment, and the code segments (entirely
separate from data) were simply numbered, so there was a function 1, a
function 2 and so on. If the C library did not change much, you got to
know that a call to, say, function 34 was printf.

Programmers of a certain age, and from this side of the Atlatic, might
know the company (though maybe not the machine) from this description
alone since the memory architecture (for a personal workstation) was
borrowed from it big brothers at the same firm.

--
Ben.

Re: Call to a function

<86il7yjsdo.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Mon, 25 Sep 2023 06:26:43 -0700
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <86il7yjsdo.fsf@linuxsc.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de> <86r0mokgu8.fsf@linuxsc.com> <87wmwgh7y0.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="b3d2a53e0ccd70cd5158b7b6e81b5d4b";
logging-data="2043022"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+loNR4QhCBORM5BTnI+RsqknhpJxIBNM="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:UdZzhreNn4Y2IftJ63GigV+vVYs=
sha1:LooFfCFyngN8d4mqIG6LcbwyhZI=
 by: Tim Rentsch - Mon, 25 Sep 2023 13:26 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

[converting integers to pointer-to-function]

>> An implementation could choose to convert an integer 1 to
>> a pointer to an actual function, because the mapping is
>> implementation defined. Of course it's very likely that it
>> won't be, but it could be.
>
> I worked on a C compiler that did just this. The machine put every
> function into it's own memory segment, and the code segments (entirely
> separate from data) were simply numbered, so there was a function 1, a
> function 2 and so on. If the C library did not change much, you got to
> know that a call to, say, function 34 was printf.

Great info! thanks.

> Programmers of a certain age, and from this side of the Atlatic, might
> know the company (though maybe not the machine) from this description
> alone since the memory architecture (for a personal workstation) was
> borrowed from it big brothers at the same firm.

I hope you realize that there is no way I could read this
and not be curious about the particulars.

Re: Call to a function

<878r8tho52.fsf@bsb.me.uk>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Mon, 25 Sep 2023 23:41:13 +0100
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <878r8tho52.fsf@bsb.me.uk>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<86r0mokgu8.fsf@linuxsc.com> <87wmwgh7y0.fsf@bsb.me.uk>
<86il7yjsdo.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="ec3b8353d514a2991d7d955d9087a71d";
logging-data="2252857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197fQ8wEzXqy0pkOQ247fbflCe+7rVf+W8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:ThSXY+AV3s3hozJ1BKwfOTZWFjw=
sha1:/gKXeoManKhTELALcbBqIMdPYqo=
X-BSB-Auth: 1.827a40ba476a9e11ec1e.20230925234113BST.878r8tho52.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 25 Sep 2023 22:41 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
> [converting integers to pointer-to-function]
>
>>> An implementation could choose to convert an integer 1 to
>>> a pointer to an actual function, because the mapping is
>>> implementation defined. Of course it's very likely that it
>>> won't be, but it could be.
>>
>> I worked on a C compiler that did just this. The machine put every
>> function into it's own memory segment, and the code segments (entirely
>> separate from data) were simply numbered, so there was a function 1, a
>> function 2 and so on. If the C library did not change much, you got to
>> know that a call to, say, function 34 was printf.
>
> Great info! thanks.
>
>> Programmers of a certain age, and from this side of the Atlatic, might
>> know the company (though maybe not the machine) from this description
>> alone since the memory architecture (for a personal workstation) was
>> borrowed from it big brothers at the same firm.
>
> I hope you realize that there is no way I could read this
> and not be curious about the particulars.

I only held off in case anyone wanted to play...

It was ICL. The workstation was the Perq from Three Rivers Corp. which
ICL licenced (or bought out right -- I don't recall) and, after some
internal wrangling, decided to make run Unix. It was a microcoded CPU
that could load and save instruction sets, so the instruction set to run
C could be designed as the compiler was being written. The design team,
being all existing ICL engineers, chose to copy some aspects of the
companies big machines. I had never worked on them, but I think the
"every function in it's own numbered segment" came from the 1900 and
2900 series mainframes.

The Perq was a wonderful piece of kit and very innovative, but that's a
poor predictor of success in the computer field. After I'd been working
on the project for a while, I was sent (almost literally undercover) to
go see what the workstation from a company no one had ever heard of was
like. In my naivety (I was a graduate hire), I reported back that that
it was not particularly fast and the graphics (and screen) were not up
to much, but that it did already have a full Unix implementation. It
was the Sun-1 workstation.

--
Ben.

Re: Call to a function

<uevc81$2lbnd$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vir.camp...@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Tue, 26 Sep 2023 20:42:56 +0100
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uevc81$2lbnd$1@dont-email.me>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<86r0mokgu8.fsf@linuxsc.com> <87wmwgh7y0.fsf@bsb.me.uk>
<86il7yjsdo.fsf@linuxsc.com> <878r8tho52.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Sep 2023 19:42:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a22ed514f616d840235f61fbde950bfd";
logging-data="2797293"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fOET8ojjT0ZSovi7SRC5db+MwmcwcgAU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:4X/ozfTRUZZMi/AS2VwFV0EUSUs=
In-Reply-To: <878r8tho52.fsf@bsb.me.uk>
Content-Language: en-GB
 by: Vir Campestris - Tue, 26 Sep 2023 19:42 UTC

On 25/09/2023 23:41, Ben Bacarisse wrote:
> I only held off in case anyone wanted to play...
>
> It was ICL. The workstation was the Perq from Three Rivers Corp. which
> ICL licenced (or bought out right -- I don't recall) and, after some
> internal wrangling, decided to make run Unix. It was a microcoded CPU
> that could load and save instruction sets, so the instruction set to run
> C could be designed as the compiler was being written. The design team,
> being all existing ICL engineers, chose to copy some aspects of the
> companies big machines. I had never worked on them, but I think the
> "every function in it's own numbered segment" came from the 1900 and
> 2900 series mainframes.
>
> The Perq was a wonderful piece of kit and very innovative, but that's a
> poor predictor of success in the computer field. After I'd been working
> on the project for a while, I was sent (almost literally undercover) to
> go see what the workstation from a company no one had ever heard of was
> like. In my naivety (I was a graduate hire), I reported back that that
> it was not particularly fast and the graphics (and screen) were not up
> to much, but that it did already have a full Unix implementation. It
> was the Sun-1 workstation.

Perq. OMG I haven't thought about that in _decades_!

I have this vague memory that there was an internal dispute about the
instruction set, and that part implementations were done on two.

IIRC (and it's very vague) it originally had a Pascal-oriented
instruction set, and it was recoded for C. But it could easily have been
the other way around! I wasn't involved, but I was near some of the guys
in BRA01 who were.

Andy

Re: Call to a function

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Wed, 27 Sep 2023 03:56:40 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <87r0mkfhnb.fsf@bsb.me.uk>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<86r0mokgu8.fsf@linuxsc.com> <87wmwgh7y0.fsf@bsb.me.uk>
<86il7yjsdo.fsf@linuxsc.com> <878r8tho52.fsf@bsb.me.uk>
<uevc81$2lbnd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="181c995184528b30fd640b41197c0512";
logging-data="3058392"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/y5k83wIaJvMPSZAnSvOInfO88oERUZ/U="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:UtcDFsFdciDm0pTFpmZR1DXnjS4=
sha1:j8Af8lTdZY40x423JcNX+292ie0=
X-BSB-Auth: 1.6cb6774164cb3dd39d83.20230927035640BST.87r0mkfhnb.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 27 Sep 2023 02:56 UTC

Vir Campestris <vir.campestris@invalid.invalid> writes:

> On 25/09/2023 23:41, Ben Bacarisse wrote:
>> I only held off in case anyone wanted to play...
>> It was ICL. The workstation was the Perq from Three Rivers Corp. which
>> ICL licenced (or bought out right -- I don't recall) and, after some
>> internal wrangling, decided to make run Unix. It was a microcoded CPU
>> that could load and save instruction sets, so the instruction set to run
>> C could be designed as the compiler was being written. The design team,
>> being all existing ICL engineers, chose to copy some aspects of the
>> companies big machines. I had never worked on them, but I think the
>> "every function in it's own numbered segment" came from the 1900 and
>> 2900 series mainframes.
>> The Perq was a wonderful piece of kit and very innovative, but that's a
>> poor predictor of success in the computer field. After I'd been working
>> on the project for a while, I was sent (almost literally undercover) to
>> go see what the workstation from a company no one had ever heard of was
>> like. In my naivety (I was a graduate hire), I reported back that that
>> it was not particularly fast and the graphics (and screen) were not up
>> to much, but that it did already have a full Unix implementation. It
>> was the Sun-1 workstation.
>
> Perq. OMG I haven't thought about that in _decades_!
>
> I have this vague memory that there was an internal dispute about the
> instruction set, and that part implementations were done on two.
>
> IIRC (and it's very vague) it originally had a Pascal-oriented instruction
> set, and it was recoded for C. But it could easily have been the other way
> around! I wasn't involved, but I was near some of the guys in BRA01 who
> were.

It came to ICL with a Pascal-oriented instruction set done by the people
at Three Rivers. The C one was largely the work of a few people at
Dalkeith. What's BRA01? Bracknell? IIRC the work was moved to Stoke
when Dalkeith was closed but I had decided to move on by then.

There was a very tentative Lisp instruction set (the OS was designed to
be able to swap instruction sets with context switches between
processes) but I don't think that was in-house. It might even have been
the work of an early customer.

--
Ben.

Re: Call to a function

<86fs30i2ud.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Tue, 26 Sep 2023 22:48:10 -0700
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <86fs30i2ud.fsf@linuxsc.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de> <86r0mokgu8.fsf@linuxsc.com> <87wmwgh7y0.fsf@bsb.me.uk> <86il7yjsdo.fsf@linuxsc.com> <878r8tho52.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="6070b16265764b9698c1f034b5979f11";
logging-data="3108968"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+G0WQsgSmcf4xbjv9CchmbO0QmIK4Jlkw="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:5qhKE6NsMTFZDIq1rl1OslV/beU=
sha1:DqGoN//eHXXOOUfdcRqpP/uJzd4=
 by: Tim Rentsch - Wed, 27 Sep 2023 05:48 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>
>>> Programmers of a certain age, and from this side of the Atlatic,
>>> might know the company (though maybe not the machine) from this
>>> description alone since the memory architecture (for a personal
>>> workstation) was borrowed from it big brothers at the same firm.
>>
>> I hope you realize that there is no way I could read this
>> and not be curious about the particulars.
>
> I only held off in case anyone wanted to play...

A laudable policy. Thank you for the followup info.

Re: Call to a function

<uf4npd$3riqm$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vir.camp...@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Thu, 28 Sep 2023 21:30:36 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <uf4npd$3riqm$1@dont-email.me>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<86r0mokgu8.fsf@linuxsc.com> <87wmwgh7y0.fsf@bsb.me.uk>
<86il7yjsdo.fsf@linuxsc.com> <878r8tho52.fsf@bsb.me.uk>
<uevc81$2lbnd$1@dont-email.me> <87r0mkfhnb.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 28 Sep 2023 20:30:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e608e4d96c5de6c682e3125f453c57c0";
logging-data="4049750"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uK91TuaNL89E02k6Kbrt+BI8D+Bn3L78="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:fK7iLHBKBjg7uAnpXLlP87abGaw=
Content-Language: en-GB
In-Reply-To: <87r0mkfhnb.fsf@bsb.me.uk>
 by: Vir Campestris - Thu, 28 Sep 2023 20:30 UTC

On 27/09/2023 03:56, Ben Bacarisse wrote:
> Vir Campestris <vir.campestris@invalid.invalid> writes:
>
>> On 25/09/2023 23:41, Ben Bacarisse wrote:
>>> I only held off in case anyone wanted to play...
>>> It was ICL. The workstation was the Perq from Three Rivers Corp. which
>>> ICL licenced (or bought out right -- I don't recall) and, after some
>>> internal wrangling, decided to make run Unix. It was a microcoded CPU
>>> that could load and save instruction sets, so the instruction set to run
>>> C could be designed as the compiler was being written. The design team,
>>> being all existing ICL engineers, chose to copy some aspects of the
>>> companies big machines. I had never worked on them, but I think the
>>> "every function in it's own numbered segment" came from the 1900 and
>>> 2900 series mainframes.
>>> The Perq was a wonderful piece of kit and very innovative, but that's a
>>> poor predictor of success in the computer field. After I'd been working
>>> on the project for a while, I was sent (almost literally undercover) to
>>> go see what the workstation from a company no one had ever heard of was
>>> like. In my naivety (I was a graduate hire), I reported back that that
>>> it was not particularly fast and the graphics (and screen) were not up
>>> to much, but that it did already have a full Unix implementation. It
>>> was the Sun-1 workstation.
>>
>> Perq. OMG I haven't thought about that in _decades_!
>>
>> I have this vague memory that there was an internal dispute about the
>> instruction set, and that part implementations were done on two.
>>
>> IIRC (and it's very vague) it originally had a Pascal-oriented instruction
>> set, and it was recoded for C. But it could easily have been the other way
>> around! I wasn't involved, but I was near some of the guys in BRA01 who
>> were.
>
> It came to ICL with a Pascal-oriented instruction set done by the people
> at Three Rivers. The C one was largely the work of a few people at
> Dalkeith. What's BRA01? Bracknell? IIRC the work was moved to Stoke
> when Dalkeith was closed but I had decided to move on by then.
>
> There was a very tentative Lisp instruction set (the OS was designed to
> be able to swap instruction sets with context switches between
> processes) but I don't think that was in-house. It might even have been
> the work of an early customer.
>
All ICL sites had a three letter town ID, plus a two digit sequence
number. A few towns had more than 9 sites. BRA01 was the main site at
Bracknell. I assumed from what you said that you worked for ICL.

Andy

Re: Call to a function

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Thu, 28 Sep 2023 21:54:07 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <87o7hmc93k.fsf@bsb.me.uk>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<86r0mokgu8.fsf@linuxsc.com> <87wmwgh7y0.fsf@bsb.me.uk>
<86il7yjsdo.fsf@linuxsc.com> <878r8tho52.fsf@bsb.me.uk>
<uevc81$2lbnd$1@dont-email.me> <87r0mkfhnb.fsf@bsb.me.uk>
<uf4npd$3riqm$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="1432f0dee4a59f52e97231a9b3a0897f";
logging-data="4056414"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GE3WsH8iq34qI2ENdVnNHsXVTRzYbDnY="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:IlpHSlpFJKIpL8nR977dGWDTpQw=
sha1:aHTDSgzh4jCEWBtiZzu2Hjq0i5A=
X-BSB-Auth: 1.31494d0afe77f83eeeb3.20230928215407BST.87o7hmc93k.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 28 Sep 2023 20:54 UTC

Vir Campestris <vir.campestris@invalid.invalid> writes:

> On 27/09/2023 03:56, Ben Bacarisse wrote:
>> Vir Campestris <vir.campestris@invalid.invalid> writes:
....
>>> Perq. OMG I haven't thought about that in _decades_!
>>>
>>> I have this vague memory that there was an internal dispute about the
>>> instruction set, and that part implementations were done on two.
>>>
>>> IIRC (and it's very vague) it originally had a Pascal-oriented instruction
>>> set, and it was recoded for C. But it could easily have been the other way
>>> around! I wasn't involved, but I was near some of the guys in BRA01 who
>>> were.
>> It came to ICL with a Pascal-oriented instruction set done by the people
>> at Three Rivers. The C one was largely the work of a few people at
>> Dalkeith. What's BRA01? Bracknell?
....
> All ICL sites had a three letter town ID, plus a two digit sequence
> number. A few towns had more than 9 sites. BRA01 was the main site at
> Bracknell. I assumed from what you said that you worked for ICL.

Yes, I did. And, from what you tell me, I probably worked at DAL01
without ever knowing what it was called!

--
Ben.

OT: ICL PERQ (was Re: Call to a function)

<uf7dq8$eg3n$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vir.camp...@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c
Subject: OT: ICL PERQ (was Re: Call to a function)
Date: Fri, 29 Sep 2023 21:58:48 +0100
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uf7dq8$eg3n$3@dont-email.me>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<86r0mokgu8.fsf@linuxsc.com> <87wmwgh7y0.fsf@bsb.me.uk>
<86il7yjsdo.fsf@linuxsc.com> <878r8tho52.fsf@bsb.me.uk>
<uevc81$2lbnd$1@dont-email.me> <87r0mkfhnb.fsf@bsb.me.uk>
<uf4npd$3riqm$1@dont-email.me> <87o7hmc93k.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Sep 2023 20:58:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="82280ea666e054db45ab96fdc8c0fa63";
logging-data="475255"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8twJshhkYxGtytGAzUyqppJBgj8nZ0Uc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:4pCa3/rvui3CXC9X7PqTq6tebrE=
Content-Language: en-GB
In-Reply-To: <87o7hmc93k.fsf@bsb.me.uk>
 by: Vir Campestris - Fri, 29 Sep 2023 20:58 UTC

On 28/09/2023 21:54, Ben Bacarisse wrote:
> Yes, I did. And, from what you tell me, I probably worked at DAL01
> without ever knowing what it was called!

Ah, Dalkeith. Other end of the country, I never got past Manchester.

And while I was looking I found this...

<http://www.chilton-computing.org.uk/acd/sus/perq_history/overview.htm>

<https://en.wikipedia.org/wiki/International_Computers_Limited#Locations>

Andy

Re: Call to a function

<86jzs3de3h.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Tue, 03 Oct 2023 06:34:26 -0700
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <86jzs3de3h.fsf@linuxsc.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de> <20230922081706.858@kylheku.com> <87zg1et4wv.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="a7f15c7033ff7991d1a910385a293cab";
logging-data="3766607"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182ZXf2RzSX+6yst7ESqCjChO700yRhkM4="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Z6F4Hc1Ux+8zlHqAloMVAe0Mu2g=
sha1:0df0CnxwEz1VzSKzJHoml1jKbyA=
 by: Tim Rentsch - Tue, 3 Oct 2023 13:34 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>
>> On 2023-09-22, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>>
>>> When "1" is cast to a function type and then this is called,
>>> one would expect this call to have undefined behavior. But
>>> I can only find this in the C specification:
>>>
>>> |If a converted pointer is used to call a function whose type
>>> |is not compatible with the referenced type, the behavior is
>>> |undefined.
>>
>> Because ISO C supports conversions between function pointer types,
>> above, the document is addressing what happens in the situation
>> when the address of a function is converted to a different pointer type,
>> which is then called. E.g. int puts(const char *) is misused as
>> a void (double) function:
>>
>> void (*fptr)(double) = (void (*)(double)) puts;
>>
>> So far, the behavior is defined: the conversion is valid.
>> The pointer could be converted to the correct type and used:
>>
>> So, the above remarks make it clear that
>>
>> fptr(3.14);
>>
>> isn't defined.
>>
>>> . At the address "1" there is not "a function whose type is not
>>> compatible", but no function at all.
>>
>> The conversion is not supported by ISO C, and so itself has
>> undefined behavior:
>>
>> void (*fptr)(double) = (void (*)(double)) 1;
>
> The original post used "1", a string literal. You assumed it was an
> integer constant in quotes.

I would say inferred rather than assumed. Clearly the OP was
using double quotes as a way of delimiting code, in much the same
way that some people use back tick (backward facing single
quotes); note that the original text also says "f()" to indicate
a function call, and there is no doubt that "f()" is not meant to
include the quotes as part of the code.

> The point is the same either way, [...]

The point isn't quite the same. The C standard explicitly says
integers may be converted to any pointer type. The C standard
does not say that a pointer to an object type may be converted
to a pointer to function type. Every implementation is within
its rights to reject any program whose static text includes[*] a
cast from a pointer to an object type to a pointer to function
type, regardless of whether the cast has any chance of being
executed.

[*] meaning, still present as source of any preprocessor
conditionals have been processed, etc.

Re: Call to a function

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Tue, 03 Oct 2023 15:13:51 -0700
Organization: None to speak of
Lines: 37
Message-ID: <87h6n7tkv4.fsf@nosuchdomain.example.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<20230922081706.858@kylheku.com>
<87zg1et4wv.fsf@nosuchdomain.example.com> <86jzs3de3h.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="9da464444b2257c989bb4d90b174d1f1";
logging-data="3968554"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YwO6yNwRJH6BSG71gPz53"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:2TvaQtp3gjgk76tmYee/+E9YeIk=
sha1:fJIwVB4PHHV/CCa8cWNG//y/Q2M=
 by: Keith Thompson - Tue, 3 Oct 2023 22:13 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
> The point isn't quite the same. The C standard explicitly says
> integers may be converted to any pointer type. The C standard
> does not say that a pointer to an object type may be converted
> to a pointer to function type. Every implementation is within
> its rights to reject any program whose static text includes[*] a
> cast from a pointer to an object type to a pointer to function
> type, regardless of whether the cast has any chance of being
> executed.
>
> [*] meaning, still present as source of any preprocessor
> conditionals have been processed, etc.

I disagree. (I think we've discussed this before.)

Concretely, I believe that this program violates no syntax error or
constraint. It includes code whose behavior would be undefined if it
were executed, but the `if (0)` prevents that.

On what basis do you think a conforming implementation may reject it?
Do you see a syntax rule or constraint that it violates? Do you see
some other basis for rejecting it?

int main(void) {
int obj = 42;
typedef void func(void);
if (0) {
func *fptr = (func*)&obj;
fptr();
}
}

--
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: Call to a function

<20231003163801.879@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Wed, 4 Oct 2023 01:52:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <20231003163801.879@kylheku.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<20230922081706.858@kylheku.com> <87zg1et4wv.fsf@nosuchdomain.example.com>
<86jzs3de3h.fsf@linuxsc.com> <87h6n7tkv4.fsf@nosuchdomain.example.com>
Injection-Date: Wed, 4 Oct 2023 01:52:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2c3a3ba67029d1579f03d8d04ca3b86b";
logging-data="4166708"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JH43G4y2pFT8GNJtrRW1G4+ePq01U748="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:C+Z3Ig7jyfLPjtJpUDp5s+swr6E=
 by: Kaz Kylheku - Wed, 4 Oct 2023 01:52 UTC

On 2023-10-03, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> [...]
>> The point isn't quite the same. The C standard explicitly says
>> integers may be converted to any pointer type. The C standard
>> does not say that a pointer to an object type may be converted
>> to a pointer to function type. Every implementation is within
>> its rights to reject any program whose static text includes[*] a
>> cast from a pointer to an object type to a pointer to function
>> type, regardless of whether the cast has any chance of being
>> executed.
>>
>> [*] meaning, still present as source of any preprocessor
>> conditionals have been processed, etc.
>
> I disagree. (I think we've discussed this before.)
>
> Concretely, I believe that this program violates no syntax error or
> constraint. It includes code whose behavior would be undefined if it
> were executed, but the `if (0)` prevents that.

The problem is that the is not required to be translatable.

The code being dead inside an if (0) doesn't rescue it.

Conversion between function and object pointers isn't something that is
only undefined at run time, but otherwise translatable.

> On what basis do you think a conforming implementation may reject it?

On the basis that it's not able to convert between object and
function pointers, and on the basis that it only eliminates dead
code that is first generated by its translation scheme.

> Do you see a syntax rule or constraint that it violates? Do you see
> some other basis for rejecting it?

The implementation can add its own constraint rule, and then
stop translation.

Undefined can cause the program to be terminated during translation or
execution, with or without a diagnostic.

Re: Call to a function

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Tue, 03 Oct 2023 19:13:55 -0700
Organization: None to speak of
Lines: 87
Message-ID: <87zg0z3zj0.fsf@nosuchdomain.example.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<20230922081706.858@kylheku.com>
<87zg1et4wv.fsf@nosuchdomain.example.com> <86jzs3de3h.fsf@linuxsc.com>
<87h6n7tkv4.fsf@nosuchdomain.example.com>
<20231003163801.879@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="9da464444b2257c989bb4d90b174d1f1";
logging-data="4174242"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wkIvIZFGwZOiiVFINS4Ay"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:YCsSzubblFjDSnDTJlafvEB8M+w=
sha1:5+Gt840qNjaUjalJDLiUDAUkZfo=
 by: Keith Thompson - Wed, 4 Oct 2023 02:13 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:
> On 2023-10-03, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> [...]
>>> The point isn't quite the same. The C standard explicitly says
>>> integers may be converted to any pointer type. The C standard
>>> does not say that a pointer to an object type may be converted
>>> to a pointer to function type. Every implementation is within
>>> its rights to reject any program whose static text includes[*] a
>>> cast from a pointer to an object type to a pointer to function
>>> type, regardless of whether the cast has any chance of being
>>> executed.
>>>
>>> [*] meaning, still present as source of any preprocessor
>>> conditionals have been processed, etc.
>>
>> I disagree. (I think we've discussed this before.)
>>
>> Concretely, I believe that this program violates no syntax error or
>> constraint. It includes code whose behavior would be undefined if it
>> were executed, but the `if (0)` prevents that.
>
> The problem is that the is not required to be translatable.

You left out a word, but I disagree.

> The code being dead inside an if (0) doesn't rescue it.
>
> Conversion between function and object pointers isn't something that is
> only undefined at run time, but otherwise translatable.

The standard doesn't talk about translatability. It says what is
allowed, and defines the behavior of *some* things that are allowed.
A cast from a function pointer type to an object pointer type,
or vice versa, satisfies the constraints for a cast operator.
(Conversions between pointer types and floating-point types are
explicitly banned. Function/object pointer conversions *could*
have been.)

Perhaps the standard would be improved by making object/function pointer
conversions not involving a null pointer constant a constraint
violation. That might break some working but non-portable code that
converts between function pointers and void*. Or perhaps the standard
could be changed to state explicitly that such conversions have
undefined behavior, but they already do due to the lack of any
definition of the behavior.

>> On what basis do you think a conforming implementation may reject it?
>
> On the basis that it's not able to convert between object and
> function pointers, and on the basis that it only eliminates dead
> code that is first generated by its translation scheme.

For most implementations, object and function pointers have the same
size and representation, and a conversion can just copy or reinterpret
the bits. For others, perhaps it could extend or truncate the result,
yielding garbage, just as (void*)(char)'x' yields garbage. Or it could
just yield a null pointer regardless of the operand. It's not plausible
that an implementation would not be *able* to perform such a conversion.

>> Do you see a syntax rule or constraint that it violates? Do you see
>> some other basis for rejecting it?
>
> The implementation can add its own constraint rule, and then
> stop translation.

What do you mean by "add its own constraint rule"? Constraints are
defined by the standard, not by an implementation. Are you suggesting
an implementation can add its own constraint for some code that the
implementer just found too difficult to handle correctly?

> Undefined can cause the program to be terminated during translation or
> execution, with or without a diagnostic.

*If* the undefined behavior can occur.

int a = 1;
const int b = 0;
if (b != 0) a /= b;

A compiler can prove that the division has undefined behavior if it's
executed. Can it reject the code because of that?

--
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: Call to a function

<ufimtk$3g6$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Tue, 3 Oct 2023 20:41:39 -0700
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <ufimtk$3g6$2@dont-email.me>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<20230922081706.858@kylheku.com> <87zg1et4wv.fsf@nosuchdomain.example.com>
<86jzs3de3h.fsf@linuxsc.com> <87h6n7tkv4.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 4 Oct 2023 03:41:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="996f45f5829faa796bb695d84a0a0fe9";
logging-data="3590"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RHMtQc8Zc3LcThM5q5QvUhxEXS0qFBsA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:ftR9x821WPJipTwNjAeVnOHCWMk=
In-Reply-To: <87h6n7tkv4.fsf@nosuchdomain.example.com>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 4 Oct 2023 03:41 UTC

On 10/3/2023 3:13 PM, Keith Thompson wrote:
> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> [...]
>> The point isn't quite the same. The C standard explicitly says
>> integers may be converted to any pointer type. The C standard
>> does not say that a pointer to an object type may be converted
>> to a pointer to function type. Every implementation is within
>> its rights to reject any program whose static text includes[*] a
>> cast from a pointer to an object type to a pointer to function
>> type, regardless of whether the cast has any chance of being
>> executed.
>>
>> [*] meaning, still present as source of any preprocessor
>> conditionals have been processed, etc.
>
> I disagree. (I think we've discussed this before.)
>
> Concretely, I believe that this program violates no syntax error or
> constraint. It includes code whose behavior would be undefined if it
> were executed, but the `if (0)` prevents that.
>
> On what basis do you think a conforming implementation may reject it?
> Do you see a syntax rule or constraint that it violates? Do you see
> some other basis for rejecting it?
>
> int main(void) {
> int obj = 42;
> typedef void func(void);
> if (0) {
> func *fptr = (func*)&obj;
> fptr();
> }
> }
>

"Saved by Zero" by the Fixx? lol

https://youtu.be/JOiZP8FS5Ww

;^)

Re: Call to a function

<86ttqf2w6p.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Tue, 24 Oct 2023 20:54:54 -0700
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <86ttqf2w6p.fsf@linuxsc.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de> <20230922081706.858@kylheku.com> <87zg1et4wv.fsf@nosuchdomain.example.com> <86jzs3de3h.fsf@linuxsc.com> <87h6n7tkv4.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="cf97bd7e9489cbbcf364cc78b48cedaf";
logging-data="541043"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19clx0E9smenPHZP/CHhBKAy16a5FFAMg8="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:uyzzGmv4siMPIW7n9xKsvvSBWCQ=
sha1:OnEyTTR7nfMnXczzz47zV9p3pms=
 by: Tim Rentsch - Wed, 25 Oct 2023 03:54 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> [...]
>
>> The point isn't quite the same. The C standard explicitly says
>> integers may be converted to any pointer type. The C standard
>> does not say that a pointer to an object type may be converted
>> to a pointer to function type. Every implementation is within
>> its rights to reject any program whose static text includes[*] a
>> cast from a pointer to an object type to a pointer to function
>> type, regardless of whether the cast has any chance of being
>> executed.
>>
>> [*] meaning, still present as source of any preprocessor
>> conditionals have been processed, etc.
>
> I disagree. (I think we've discussed this before.)
>
> Concretely, I believe that this program violates no syntax error
> or constraint. It includes code whose behavior would be undefined
> if it were executed, but the `if (0)` prevents that.
>
> On what basis do you think a conforming implementation may reject
> it?

First let me ask a question. Does the C standard allow an
implementation to reject any program that is not strictly
conforming?

Re: Call to a function

<uha5fs$2mvvu$1@i2pn2.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!.POSTED!not-for-mail
From: rich...@damon-family.org (Richard Damon)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Tue, 24 Oct 2023 21:27:40 -0700
Organization: i2pn2 (i2pn.org)
Message-ID: <uha5fs$2mvvu$1@i2pn2.org>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<20230922081706.858@kylheku.com> <87zg1et4wv.fsf@nosuchdomain.example.com>
<86jzs3de3h.fsf@linuxsc.com> <87h6n7tkv4.fsf@nosuchdomain.example.com>
<86ttqf2w6p.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 25 Oct 2023 04:27:40 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="2850814"; mail-complaints-to="usenet@i2pn2.org";
posting-account="diqKR1lalukngNWEqoq9/uFtbkm5U+w3w6FQ0yesrXg";
User-Agent: Mozilla Thunderbird
In-Reply-To: <86ttqf2w6p.fsf@linuxsc.com>
Content-Language: en-US
 by: Richard Damon - Wed, 25 Oct 2023 04:27 UTC

On 10/24/23 8:54 PM, Tim Rentsch wrote:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> [...]
>>
>>> The point isn't quite the same. The C standard explicitly says
>>> integers may be converted to any pointer type. The C standard
>>> does not say that a pointer to an object type may be converted
>>> to a pointer to function type. Every implementation is within
>>> its rights to reject any program whose static text includes[*] a
>>> cast from a pointer to an object type to a pointer to function
>>> type, regardless of whether the cast has any chance of being
>>> executed.
>>>
>>> [*] meaning, still present as source of any preprocessor
>>> conditionals have been processed, etc.
>>
>> I disagree. (I think we've discussed this before.)
>>
>> Concretely, I believe that this program violates no syntax error
>> or constraint. It includes code whose behavior would be undefined
>> if it were executed, but the `if (0)` prevents that.
>>
>> On what basis do you think a conforming implementation may reject
>> it?
>
> First let me ask a question. Does the C standard allow an
> implementation to reject any program that is not strictly
> conforming?

No, to reject a program it must violate some constraint.

Not being 'strictly conforming' (a technical term in the Standard) is
not a requirement for a program to be accepted.

Now, there is the escape clause, that allows an implementation to fail
to actually be able to run anything but the one specified program that
meets all the minimum requirements, but that isn't grounds to 'reject'
programs.

Re: Call to a function

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Call to a function
Date: Tue, 24 Oct 2023 21:58:38 -0700
Organization: None to speak of
Lines: 58
Message-ID: <87zg07jo1t.fsf@nosuchdomain.example.com>
References: <call-20230922130647@ram.dialup.fu-berlin.de>
<20230922081706.858@kylheku.com>
<87zg1et4wv.fsf@nosuchdomain.example.com> <86jzs3de3h.fsf@linuxsc.com>
<87h6n7tkv4.fsf@nosuchdomain.example.com> <86ttqf2w6p.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4d3dc32917782594b2126b84973b1030";
logging-data="569777"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3JNajzYpkritM+giCQ9d6"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:7K3NUe7zNEyB1grN8XKnKzgIK3E=
sha1:tYez/jXcWji2adry2FuVLn5PcRE=
 by: Keith Thompson - Wed, 25 Oct 2023 04:58 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> [...]
>>> The point isn't quite the same. The C standard explicitly says
>>> integers may be converted to any pointer type. The C standard
>>> does not say that a pointer to an object type may be converted
>>> to a pointer to function type. Every implementation is within
>>> its rights to reject any program whose static text includes[*] a
>>> cast from a pointer to an object type to a pointer to function
>>> type, regardless of whether the cast has any chance of being
>>> executed.
>>>
>>> [*] meaning, still present as source of any preprocessor
>>> conditionals have been processed, etc.
>>
>> I disagree. (I think we've discussed this before.)
>>
>> Concretely, I believe that this program violates no syntax error
>> or constraint. It includes code whose behavior would be undefined
>> if it were executed, but the `if (0)` prevents that.
>>
>> On what basis do you think a conforming implementation may reject
>> it?
>
> First let me ask a question. Does the C standard allow an
> implementation to reject any program that is not strictly
> conforming?

Not just for that reason.

This program:

#include <stdio.h>
int main(void) {
printf("%zu\n", sizeof (int));
}

is not strictly conforming, since it depends on the
implementation-defined size of int. A hosted implementation that
rejected it would violate 4p3:

A program that is correct in all other aspects, operating on correct
data, containing unspecified behavior shall be a correct program and
act in accordance with 5.1.2.3.

(A perverse implementation could claim that it exceeds its capacity, but
I think we can ignore that.)

What is your answer to your own question?

And I hope we're not going to go back and forth too many times before
you answer mine.

--
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 */

Pages:1234
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor