Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: function pointer question Date: Tue, 06 Jan 2026 17:01:40 -0800 Organization: None to speak of Lines: 36 Message-ID: <87cy3m2q2z.fsf@example.invalid> References: <10j7rs6$7c9e$1@dont-email.me> <20260102091518.226@kylheku.com> <10j96mn$jrsp$1@dont-email.me> <10j9enb$p6ts$2@dont-email.me> <10j9g71$pr9o$1@dont-email.me> <10jb3j5$17gcb$3@dont-email.me> <20260106123319.105@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Wed, 07 Jan 2026 01:01:41 +0000 (UTC) Injection-Info: dont-email.me; posting-host="6f871b5ffe12a84f74a2becf62529d59"; logging-data="288036"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uNJ+knI7NuekewOPop1q2" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:xyoBytbFNMA6GufkPSunv/Px7bM= sha1:bG3cjDDyFHQtORJx169VQuIsjgI= Xref: csiph.com comp.lang.c:396238 Kaz Kylheku <046-301-5902@kylheku.com> writes: > On 2026-01-03, David Brown wrote: [...] >> Kaz mentioned several types that "void *" is a generic /object/ pointer. >> Functions are not objects - pointers to functions are completely >> different from pointers to objects. You can't mix them without "I know >> what I am doing" explicit casts, with non-portable behaviour and a >> serious risk of UB. > > "I know that I'm on POSIX" goes a long way also. Sort of. POSIX doesn't guarantee that all function pointers can be converted to void* without loss of information. It makes that guarantee only for pointers returned by dlsym(). https://pubs.opengroup.org/onlinepubs/9799919799/functions/dlsym.html On the other hand, I'd be surprised if there were any POSIX-conforming implementation that don't make that guarantee for all function pointers. There are some tricks that could be played to satisfy the dlsym() requirement even if function pointers are bigger than void*, but I've never heard of an implementation that did anything like that. (For example, say the system has 64-bit function pointers and 32-bit void*. The implementation could arrange for every function referenced by dlsym() to have an address with its upper 32 bits set to zero, perhaps by using small wrapper functions. Other functions might have arbitrary addresses so converting them to void* would lose information.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */