Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #101454
| From | Noob <root@127.0.0.1> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Function pointers conversions and UB |
| Date | 2017-01-11 21:26 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <o564ak$fjf$1@dont-email.me> (permalink) |
Hello,
Consider the following code:
void foo(struct s *arg) { }
void (*fp)(void *) = foo;
As far as I understand, this does /not/ have UB, because fp is not used
to call the function. Is that correct?
C99 6.3.2.3 p8
"A pointer to a function of one type may be converted to a pointer to a function of another
type and back again; the result shall compare equal to the original pointer. If a converted
pointer is used to call a function whose type is not compatible with the pointed-to type,
the behavior is undefined."
So the following code does have UB, correct?
void foo(struct s *arg) { }
void (*fp)(void *) = foo;
void bar(void) { fp(); } /* nasal demons from fp() */
I assume the behavior will be "it works as expected" on most platforms.
How/where will it blow up?
Platforms with different argument passing for void * and other pointers?
I lack imagination... What else? Pointer representation/encoding?
Regards.
Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread
Function pointers conversions and UB Noob <root@127.0.0.1> - 2017-01-11 21:26 +0100
Re: Function pointers conversions and UB "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-11 15:57 -0500
Re: Function pointers conversions and UB supercat@casperkitty.com - 2017-01-11 14:37 -0800
Re: Function pointers conversions and UB jt@toerring.de (Jens Thoms Toerring) - 2017-01-11 21:46 +0000
Re: Function pointers conversions and UB Keith Thompson <kst-u@mib.org> - 2017-01-11 13:51 -0800
Re: Function pointers conversions and UB "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-11 17:06 -0500
Re: Function pointers conversions and UB Noob <root@127.0.0.1> - 2017-01-12 00:29 +0100
Re: Function pointers conversions and UB Richard Heathfield <rjh@cpax.org.uk> - 2017-01-11 23:37 +0000
Re: Function pointers conversions and UB supercat@casperkitty.com - 2017-01-11 21:49 -0800
Re: Function pointers conversions and UB Richard Heathfield <rjh@cpax.org.uk> - 2017-01-12 09:41 +0000
Re: Function pointers conversions and UB Noob <root@127.0.0.1> - 2017-01-12 10:52 +0100
Re: Function pointers conversions and UB Richard Heathfield <rjh@cpax.org.uk> - 2017-01-12 09:58 +0000
Re: Function pointers conversions and UB Noob <root@127.0.0.1> - 2017-01-12 13:08 +0100
Re: Function pointers conversions and UB Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-12 13:45 +0000
csiph-web