Path: csiph.com!news.mixmin.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: Mon, 09 Oct 2023 17:15:04 -0700 Organization: None to speak of Lines: 42 Message-ID: <87zg0rtjsn.fsf@nosuchdomain.example.com> References: <20231007235448.25c4986f123c88ff65d2f103@gmail.moc> <20231008125543.518cab44cdefed7e8af393c8@gmail.moc> <87cyxovj92.fsf@nosuchdomain.example.com> <20231009230651.433f6ac34e4597e3b015f019@gmail.moc> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: dont-email.me; posting-host="22bf231b5b8ebc319b1c8a1413823473"; logging-data="222368"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UlREb9QUXse1oJEPBHZUs" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:67b8lUUXcbJvzZ4LAVB1o1yRA6Q= sha1:w7JWOJz5aZnKN1KBxt9LT/X88G4= Xref: csiph.com comp.lang.c++:92497 comp.lang.c:198374 Anton Shepelev writes: > Keith Thompson to Blue-Maned_Hawk: >> > The return value from dlsym(), cast to a pointer to the >> > type of the named symbol, can be used to call (in the >> > case of a function) or access the contents of (in the >> > case of a data object) the named symbol. >> >> An implementation could satisfy that requirement without >> supporting void* to function pointer conversions in >> general. > > Sounds a like an unnecessary special case and a loophole, > when a standard solution exists: > > Message-ID: <20231009230305.adfd0d80c146dc966ab22443@gmail.moc> > Archived : http://al.howardknight.net/?ID=169688196000 dlsym() *is* a standard solution. It's specified by the POSIX standard, which imposes some additional requirements on top of those imposed by the ISO C standard. For example, a conforming C implementation with 16-bit int cannot conform to POSIX, which requires INT_MAX >= 2147483647. My remark about an implementation using special-case code to narrowly support dlsym() was mostly theoretical. I doubt that any real-world system exists which supports POSIX on which converting a function pointer to void* and back again doesn't yield a valid copy of the original function pointer. I agree that it would have been cleaner if POSIX had specified two different dlsym() functions, one for objects and one for functions. Another post in this thread suggests that dlsym() originated with SunOS, some time around 1990. That was after C90 was published, but I can imagine that it or something like it was introduced earlier. The current dlsym() specification is a bit sloppy, but as far as I can tell that hasn't created any problems in practice. -- 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 */