Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: =?utf-8?Q?=E2=80=9CChattyG?= takes a college freshman C/C++ programming =?utf-8?Q?exam=E2=80=9D?= Date: Fri, 13 Oct 2023 10:04:31 -0700 Organization: None to speak of Lines: 55 Message-ID: <87h6musbc0.fsf@nosuchdomain.example.com> References: <20231007235448.25c4986f123c88ff65d2f103@gmail.moc> <20231008125543.518cab44cdefed7e8af393c8@gmail.moc> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: dont-email.me; posting-host="955fe9b56d1a5da4a1229feed6cf9740"; logging-data="3471753"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IE7sWFtsurvkG6ByrqP1X" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:lWtC9vP6OeTI3nEu/fnp1EzS/XM= sha1:7GjZTQKts7JDn02VqLHDG/XOPUw= Xref: csiph.com comp.lang.c++:92785 comp.lang.c:249413 MarioCCCP writes: > On 08/10/23 21:31, 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? > > mine is not an answer but a doubt : maybe void * and void (*) (void) > could require different alignment restrictions ? > > I dunno whether or not void * has any restriction at all ... It does. Object pointers can be converted to void* and back without loss of information. Quoting the C standard: A pointer to void may be converted to or from a pointer to any object type. A pointer to any object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer. Function pointers can be converted to other function pointer types and back again without loss of information. Quoting the C standard again: 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 referenced type, the behavior is undefined. But conversions between object pointer types (including void*) and function pointer types have undefined behavior. Many implementations do support meaningful conversion between function pointer types and void* (and POSIX requires such conversions to work at least for values returned by dlsym()). On most implementations, all pointers have the same representation, but that's not required. A conforming implementation could, for example, have 64-bit object pointers and 128-bit function pointers. -- 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 */