Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #176208
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Call to a function |
| Date | 2023-09-22 11:54 -0700 |
| Organization | None to speak of |
| Message-ID | <87zg1et4wv.fsf@nosuchdomain.example.com> (permalink) |
| References | <call-20230922130647@ram.dialup.fu-berlin.de> <20230922081706.858@kylheku.com> |
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 */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Call to a function Kaz Kylheku <864-117-4973@kylheku.com> - 2023-09-22 15:21 +0000
Re: Call to a function James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-09-22 11:39 -0400
Re: Call to a function Kaz Kylheku <864-117-4973@kylheku.com> - 2023-09-22 16:47 +0000
Re: Call to a function James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-09-23 01:26 -0400
Re: Call to a function Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-09-23 07:38 -0700
Re: Call to a function Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-09-22 11:54 -0700
Re: Call to a function Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-10-03 06:34 -0700
Re: Call to a function Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-10-03 15:13 -0700
Re: Call to a function Kaz Kylheku <864-117-4973@kylheku.com> - 2023-10-04 01:52 +0000
Re: Call to a function Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-10-03 19:13 -0700
Re: Call to a function "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-03 20:41 -0700
csiph-web